安装当前最新版本的nexus,安装教程网上搜,不多说了。
因为nexus3x版本没有2x版本中内置的3rd_part,所以不能在界面中上传jar包,必须使用maven的命令行。
添加第三方仓库,名字叫3rd_part
添加到maven-public组中
添加一个开发用户:用户名deployment,密码deployment123
2.如下操作在项目组成员电脑操作都可以的.
找到.m2/setting.xml
或者 maven安装目录/conf/setting.xml
文件,找到里面的 <servers>
节点,添加如下配置:
<server>
<id>base-3rdPart</id>
<username>22222</username>
<password>1111111</password>
</server>
- 1
- 2
- 3
- 4
- 5
id:待会输入命令的时候需要用到
username:表示Nexus服务器的登陆账号
password:表示Nexus服务器的登陆密码
设置上传权限:
打开cmd,上传命令(如果没有配置环境变量先去到“maven安装目录/bin/“目录下才能找到mvn命令):
mvn deploy:deploy-file -DgroupId=cmccsi -DartifactId=jodconverter -Dversion=3.0.9 -Dpackaging=jar -Dfile=D:\java\jodconverter-core-3.0-beta-4.jar -Durl=http://ip:8081/repository/3rd_part/ -DrepositoryId=base-3rdPart
DgroupId、DartifactId、Dversion:构成了该jar包在pom.xml的坐标,自己起名字也是可以的.
Dpackaging:表示打包类型.
Dfile:表示需要上传的jar包的绝对路径.
Durl:私服上第三方仓库的地址,打开nexus——>repositories菜单,可以看到该路径。
DrepositoryId:服务器的表示id,就是我们在setting.xml文件中配置的serverId。
运行结果:
1.maven私服nexus3上传jar包报错如下:
C:\Users\zheng>mvn deploy:deploy-file -DgroupId=org.jeewx -DartifactId=jeewx-api -Dversion=1.1-SNAPSHOT -Dpackaging=jar -Dfile=E:\EclipseProject\SmartCityService\doc\org\jeewx\jeewx-api\1.1-SNAPSHOT\jeewx-api-1.1-SNAPSHOT.jar -Durl=http://192.168.1.112:8081/repository/maven-releases/ -DrepositoryId=nexus
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom ---
Downloading: http://192.168.1.112:8081/repository/maven-releases/org/jeewx/jeewx-api/1.1SNAPSHOT/maven-metadata.xml
[WARNING] Could not transfer metadata org.jeewx:jeewx-api:1.1SNAPSHOT/maven-metadata.xml from/to nexus (http://192.168.1.112:8081/repository/maven-releases/): Failed to transfer file: http://192.168.1.112:8081/repository/maven-releases/org/jeewx/jeewx-api/1.1SNAPSHOT/maven-metadata.xml. Return code is: 400 , ReasonPhrase:Repository version policy: RELEASE does not allow metadata in path: org/jeewx/jeewx-api/1.1SNAPSHOT/maven-metadata.xml.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.165 s
[INFO] Finished at: 2017-03-27T14:57:42+08:00
[INFO] Final Memory: 11M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: Failed to retrieve remote metadata org.jeewx:jeewx-api:1.1SNAPSHOT/maven-metadata.xml: Could not transfer metadata org.jeewx:jeewx-api:1.1SNAPSHOT/maven-metadata.xml from/to nexus (http://192.168.1.112:8081/repository/maven-releases/): Failed to transfer file: http://192.168.1.112:8081/repository/maven-releases/org/jeewx/jeewx-api/1.1SNAPSHOT/maven-metadata.xml. Return code is: 400 , ReasonPhrase:Repository version policy: RELEASE does not allow metadata in path: org/jeewx/jeewx-api/1.1SNAPSHOT/maven-metadata.xml. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
2.解决办法
我试验后发现是自己上传的jar包的-Dversion=1.1-SNAPSHOT和jeewx-api-1.1-SNAPSHOT.jar包的后面同名所致,所以修改版本号就可以解决的,一般建议版本号用数字命名不建议用英文;