在项目开发,使用maven构建过程中,有些时候需要把本地编译好的jar包上传至远程maven私服上。
操作方法除了在Nexus后台Artifact Upload界面操作上传外,还可使用mvn的deploy命令发布jar.
以上传jedis-2.8.1.6.jar 包为例.
假设本地(windos)已经安装有apache-maven环境,目录为 C:\apache-maven-3.3.9
一、 cmd命令行切到bin目录下(或配置mvn命令的环境变量)
二、执行命令:
mvn deploy:deploy-file -Dmaven.test.skip=true -Dfile=C:\jedis-2.8.1.6.jar -DgroupId=redis.clients -DartifactId=jedis -Dversion=2.8.1.6 -Dpackaging=jar -DrepositoryId=releases -Durl=http://192.168.109.74:8081/nexus/content/repositories/releases/
成功执行会有如下提示
[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 ---
Uploading: http://192.168.109.74:8081/nexus/content/repositories/releases/redis/clients/jedis/2.8.1.6/jedis-2.8.1.6.jar
Uploaded: http://192.168.109.74:8081/nexus/content/repositories/releases/redis/clients/jedis/2.8.1.6/jedis-2.8.1.6.jar (531 KB at 1727.5 KB/sec)
Uploading: http://192.168.109.74:8081/nexus/content/repositories/releases/redis/clients/jedis/2.8.1.6/jedis-2.8.1.6.pom
Uploaded: http://192.168.109.74:8081/nexus/content/repositories/releases/redis/clients/jedis/2.8.1.6/jedis-2.8.1.6.pom (393 B at 2.8 KB/sec)
Downloading: http://192.168.109.74:8081/nexus/content/repositories/releases/redis/clients/jedis/maven-metadata.xml
Uploading: http://192.168.109.74:8081/nexus/content/repositories/releases/redis/clients/jedis/maven-metadata.xml
Uploaded: http://192.168.109.74:8081/nexus/content/repositories/releases/redis/clients/jedis/maven-metadata.xml (302 B at 3.5 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.339 s
[INFO] Finished at: 2018-10-27T12:18:10+08:00
[INFO] Final Memory: 9M/155M
[INFO] ------------------------------------------------------------------------
也可用相同方法将Jar上传至snapshots目录。