maven 上传jar 包 到nexus 私服

时间:2021-10-03 09:07:22

maven 上传jar 包 到nexus 私服

打开  eclipse: ->run as ->Maven build

goals: 执行内容如下:

deploy:deploy-file 

-DgroupId=com.baidu.aip       //groupId

 -DartifactId=baidu-json-20160810  //artifactId

 -Dversion=1.0.1-SNAPSHOT   //version

 -Dpackaging=jar 

-Dfile=C:/Users/dell/Desktop/aip-speech-java-sdk-1.0.1/json-20160810.jar    //本地jar包地址

-Durl=http://192.168.1.22:8081/repository/maven-snapshots                   //上传nexus 私服地址

-DrepositoryId=snapshots





maven deploy到nexus报错:Return code is: 401, ReasonPhrase:Unauthorized

提交到nexus时候报错:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project *: Failed to deploy artifacts: Could not transfer artifact *:jar:1.0 from/to releases (http://10.1.81.199:8081/nexus/content/repositories/releases/): Failed to transfer file: http://10.1.81.199:8081/nexus/content/repositories/releases/com/cs2c/security-management-client* /1.0/*-1.0.jar. Return code is: 401, ReasonPhrase:Unauthorized.

原来是没有配置认证。

maven目录conf的setting.xml里,


  1. <server>  
  2.     <id>releases</id>  
  3.     <username>admin</username>  
  4.     <password>admin123</password>  
  5.   </server>  
  6.  <server>  
  7.   <id>snapshots</id>  
  8.   <username>admin</username>  
  9.   <password>admin123</password>  
  10.   </server>  
  11. </servers>  

用户名和密码都是nexus的。再次deploy即可。

注意这里的id要和pom.xml里远程deploy的地址对应一致,我的pom.xml里配置:

  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>