手动上传jar包到远程仓库
前言:通常允许上传的远程仓库有两种:Snapshots和Releases,分别为快照版仓库和稳定版仓库。 快照版仓库用于存放不稳定的开发包,稳定版仓库用于存放稳定的包。
解决方案有两个:
1、通过Nexus UI 界面部署
有时候有个jar文件你无法从公共Maven仓库找到,但是你能从其它得到这个jar文件(甚至是POM),那么你完全可以将这个文件部署到Nexus中,使其成为标准流程的一部分。步骤如下:
点击左边导航栏的"Repository",在右边的仓库列表中选择一个仓库,如“3rd Party”,然后找到下面的tab,选择最后一个“Artifact Upload”,你会看到构件上传界面。选择你要上传的构件,并指定POM,(或者手工编写GAV等信息),最后点击Upload,该构件就直接被部署到了Nexus的"3rd
Party"仓库中。如图:

2、通过Maven命令行部署
maven package:打包到本项目,一般是在项目target目录下。
maven install:打包会安装到本地仓库。
maven deploy:将打包的文件发布到远程仓库(私服),提供其他人员进行下载依赖。==》这个在本地仓库也会生成

注:认证 id 这个必须和 nexus DrepositoryId 对应的仓库标识(id)一致,那么怎么查看仓库 ID 呢?

如下图
Nexus2.12.0-01

OSS 3.6.0-02版本界面如下

别人生成好的 jar 的 pom 配置信息如下:

打开CMD,将其定位到你要上传的jar包的文件夹,类似的输入以下命令:(加粗的位置要一一对应)
mvn deploy:deploy -file-DgroupId=com.zhenai.dakehu -DartifactId=dakehu-commons -Dversion=1.0.0-SNAPSHOT-Dpacckaging=jar -Dfile=dakehu-commons-1.0.0-SNAPSHOT.jar -DrepositoryId=maven-snapshots -Durl=http://112.124.33.150:8081/repository/maven-snapshots/
-Dversion 版本信息
-DrepositoryId 仓库标识id
-Durl 私服上仓库的位置,打开nexus——>repositories菜单,可以看到该路径。
-Dfile 直接写文件名即可
如果cmd 当前路径与jar包的路径在同一文件夹下,如果不在同一个目录下,需要在-Dfile 后面写上文件的绝对路径。
deploy 上传遇到的问题:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file
(default-cli) on project standalone-pom: Failed to deploy artifacts: Could not transfer artifact
com.zhenai.dakehu:dakehu-commons:jar:1.0.0-20171212.105921-1 from/to
maven-snapshots (http://112.124.33.150:8081/repository/maven-snapshots/): Failed to
transfer file:http://112.124.33.150:8081/repository/maven-snapshots/com/zhenai/dakehu/dakehu-commons/1.0.0-SNAPSHOT/dakehu-commons-1.0.0-20171212.105921-1.jar.
Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1] ===> 用户验证失败
说一下我遇到的问题:
1、neuxs 默认的帐号密码 admin/admin123,同事偷偷把密码改为 admin1234
2、maven setting.xml 中仓库认证的 id 不对
<id>maven-snapshots</id> // ===》这个必须和 nexus DrepositoryId 对应的仓库标识(id)一致