Maven deploy配置方法

来源:互联网 发布:电视会被网络取代吗 编辑:程序博客网 时间:2024/06/07 06:57

作用

在本地的pom文件配置好之后,执行deploy命令,可以将maven所打的jar包上传到远程的repository,便于其他开发者和工程共享。

pom.xml配置

首选,在pom文件中project标签下添加如下代码:

<distributionManagement>     <repository>       <id>releases</id>       <name>Internal Releases</name>       <url>http://localhost:8081/nexus/content/repositories/thirdparty</url>     </repository>     <snapshotRepository>       <id>releases</id>       <name>Internal Releases</name>       <url>http://localhost:8081/nexus/content/repositories/thirdparty</url>     </snapshotRepository> </distributionManagement> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

此时,执行deploy命令,会返回401错误,则需要用户验证或验证的信息有误。

setting.xml文件配置

在setting配置文件的servers标签下添加如下代码:

    <server>         <id>releases</id>         <username>admin</username>         <password>admin</password>       </server>  
  • 1
  • 2
  • 3
  • 4
  • 5

PS:其中此处的id,必须为pom文件中配置的repository的id。

注意事项

一般继承 parent 的version会按照如下格式写:

    <parent>          <groupId>module.some</groupId>          <artifactId>module_parent</artifactId>          <version>${parent.version}</version>      </parent>  
  • 1
  • 2
  • 3
  • 4
  • 5

这样写方便统一管理版本信息,但发布到maven私服之后,maven 会试图下载 module_parent 的 ${parent.version} 的 jar。显然,这个jar是不存在的。那么为什么已经指定了 parent.version 的值了却没有解析呢?这是因为deploy 的过程中,parent 标签里的变量是不会解析的,必须是一个常量。

结果

执行maven deploy命令成功之后,登录私服进行查询,即可看到对应的jar包。

参考文章:http://blog.csdn.net/wujun8/article/details/39495629