1.引言
在一个公司当中往往会搭建自己的nexus私服,在本篇博客中主要介绍如何搭建自己的私服,如何将自己的jar发布到私服。
2.搭建nexus私服
2.1安装nexus私服
- 下载nexus,在本篇博客中用到的是war版本,下载地址为:nexus
- 将改war包复制到tomcat的webapp目录下(修改为nexus.war),如图所示:
- 启动tomcat,在浏览器输入http://localhost:8080/nexus,出现一下界面便安装成功。
2.2登录nexus私服
- nexus私服的有着默认的用户名和密码(用户名:admin,密码:admin123)
2.3介绍nexus仓库
仓库的类型:
proxy :代理仓库,代理中央仓库的jar包
hosted :宿主仓库,改仓库属于公司私有的
3rd part:第三方的jar包,但是该jar包没有在中心仓库保存
snapshot:本公司测试版本、镜像版本
release:本公司的发行版本
public :仓库组的概念,我们实际上是用仓库组
仓库的是路径:Repository Path属性
- 仓库在服务器硬盘路径(点击仓库名称->仓库的配置->仓库地址):
远程仓库地址:
本地仓库地址:
- 查看仓库组查找顺序
查找顺序:releases->snapshots->3rd party->central
2.4开发中使用私服
- 在代码开发过程中,首先修改pom.xml文件,让本地仓库去私服查找
<!-- 没有私服:
本地仓库找不到,则访问中心仓库
有私服:
首先访问本地仓库
本地仓库没有,则访问私服仓库
私服仓库也没有,则访问中心仓库
-->
<!--
加载的是 第三方项目使用的jar包
snapshots:设置为true是说,我可以下载测试版本(不建议)
url:因为我的私服是在本机,所以是localhost
-->
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>public</id>
<name>public</name>
<url>http://localhost:8080/nexus/content/groups/public/</url>
</repository>
</repositories>
<!-- 加载的是maven生命周期插件的jar包 -->
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>public</id>
<name>public</name>
<url>http://localhost:8080/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
- 如果我们开发的jar需要部署到私服,需要设置
distributionManagement
(POM.xml)
<distributionManagement>
<!-- 发布到 快照版本的仓库,即 测试版本仓库 -->
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8080/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<!-- 发布到 发行版本的仓库中,也可以发布到3rd party 仓库 -->
<repository>
<id>releases</id>
<url>http://localhost:8080/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
- 如果发布到私服还需要设置
server
,私服的账户名密码(POM.XML)
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
- 如果发布到私服,也可以设置setting 文件(也就是全局的)
2.5需要注意地方
- xml的标签属性不要随便写(要和私服的id对应)例如:
3.总结
在本篇博客中主要介绍了:
- 如果搭建自己的私服
- 如果上传自己的jar到私服
- 如果修改pom.xml从私服下载jar