下载Nexus服务器
进入Sonatype Nexus的下载页面
image.png
下载nexus的windows版本程序包
运行Nexus服务器
解压nexus程序包到任意目录,在cmd中执行:nexus.exe/run
命令,启动nexus服务。
等待服务启动完毕,在浏览器中输入
进入nexus服务器的操作页面
创建nexus仓库
- 点击页面右上角的登录按钮Sign In按钮。使用默认的账号登录:
用户名:admin。密码:admin123
-
点击下图中的齿轮图标,进入配置nexus服务器页面。
image.png -
选择左侧栏目中的repository。点击右侧面板的Create repository按钮,进入如下页面。
image.png
选择其中的maven2(hosted)
输入仓库的名字,并在页面下方的Deployment Policy中选择Allow Deploy。
至此,自己的repository已经创建完毕。
上传jar包到nexus私服
配置本机maven server认证信息。
- 打开本机maven安装目录/conf/settings.xml文件。找到servers标签,增加如下配置:
<server>
<!--本机nexus仓库名称-->
<id>3rdParty</id>
<!--本机nexus仓库用户名-->
<username>admin</username>
<!--本机nexus仓库密码-->
<password>admin123</password>
</server>
通过命令行上传
执行如下命令:
mvn deploy:deploy-file -DgroupId=xxx.groupId -DartifactId=xxx-artifactId -Dversion=x.x.x -Dpackaging=jar -Dfile=C:\xxx.jar -Durl=http://localhost:8081/repository/3rdParty/ -DrepositoryId=3rdParty
其中:
- -DgroupId: jar包的group id
- -DartifactId:jar包的artifact id
- -Dversion:jar包的版本信息
- -Dfile:jar包的路径
- -Durl:maven仓库的URL
- -DrepositoryId:maven仓库的id
通过项目中运行maven deploy上传
创建maven项目,编写代码。
配置项目的pom.xml文件,增加如下配置项
<packaging>jar</packaging>
<distributionManagement>
<repository>
<id>3rdParty</id>
<url>http://localhost:8081/repository/3rdParty/</url>
</repository>
</distributionManagement>
- 执行命令
mvn deploy
项目jar包会自动上传至nexus指定的仓库内。