maven的package和install區別

1,

項目A 以來項目B,   B項目 如果只是執行 clean,package的話,只是打包到B項目的target 下面,  再編譯項目A 的時候一覽會報編譯錯誤,原因是項目B沒有執行install。

所以package 只是打包到target下,   install是打包安裝到我的本地maven倉庫。


2,

deploy: 打包到私服

在setting.xml文件中增加用戶名和密碼配置(特別注意這裏的ID)

 

複製代碼
    <servers>
        <!-- 用於發佈正式版本 -->
        <server>
            <id>maven-repository-releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <!-- 用於發佈快照版本 -->
        <server>
            <id>maven-repository-snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
複製代碼

 

2、在項目的pom.xml中增加以下內容

複製代碼
    <build>
        <plugins>
            <!-- 要將源碼放上去,需要加入這個插件 -->
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <repository>
            <!-- 這裏的ID要和setting的id一致 -->
            <id>maven-repository-releases</id>
            <url>http://ip:8081/nexus/content/repositories/thirdparty/</url>
        </repository>
        <!--這是打成快照版本的配置,如果不用這個snapshotRepository標籤,打包失敗,會報權限問題 -->
        <snapshotRepository>
            <id>maven-repository-snapshots</id>
            <url>http://ip:8081/nexus/content/repositories/thirdparty</url>
        </snapshotRepository>
    </distributionManagement>
複製代碼

 

3.執行Maven build的deploy命令


————摘自其他博文——————

先設置pom文件裏的build信息,可以是maven-compiler-plugin插件

maven目錄conf的setting.xml裏:

[html] view plain copy
  1. </servers>    
  2.  <server>    
  3.     <id>releases</id>    
  4.     <username>admin</username>    
  5.     <password>admin123</password>    
  6.   </server>    
  7.  <server>    
  8.   <id>snapshots</id>    
  9.   <username>admin</username>    
  10.   <password>admin123</password>    
  11.   </server>    
  12. </servers>    

pom文件添加如下,這裏的id上面的id要對應,name無所謂

[html] view plain copy
  1. <!-- 配置遠程發佈到私服,mvn deploy -->    
  2. <distributionManagement>    
  3.     <repository>    
  4.         <id>releases</id>    
  5.         <name>Nexus Release Repository</name>    
  6.         <url>http://10.1.81.199:8081/nexus/content/repositories/releases/</url>    
  7.     </repository>    
  8.     <snapshotRepository>    
  9.         <id>snapshots</id>    
  10.         <name>Nexus Snapshot Repository</name>    
  11.         <url>http://10.1.81.199:8081/nexus/content/repositories/snapshots/</url>    
  12.     </snapshotRepository>    
  13. </distributionManagement>    

沒有權限去管理界面查看DeploymentPolicy設置爲Allow Redeploy


發佈了20 篇原創文章 · 獲贊 16 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章