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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章