首先要明确仓库的概念 一、仓库:本地仓库、第三方仓库(内部中心仓库\私服)、中央仓库。{曾经刚学习的时候一度认为私服是本地仓库,要区分开,本仓库是你.m2文件夹下的repository,私服是你或者公司搭建的{可以存在本地,也可以是远端私服}}。
接着nexus安装,这个可以自行百度,我捡一些重要的说了。
二、 1.访问地址http://localhost:8081/nexus;如果tomcat就是指定端口,登录用户名密码默认admin\admin123
2、仓库目录\sonatype-work\nexus\下的indexer文件夹下存放jar包坐标索引;\sonatype-work\nexus\storage\中central存储私服从中央仓库下载下的jar包,releases存储项目发布版(deploy),snapshots存放项目测试版,public是用于整合central、releases、snapshots,后期用于私服上jar包下载
3、私服仓库的每一个物理地址对应私服网站上的路径,以及public可以配置包含哪几个仓库路径整合
三、 项目发布到私服和从私服下载需要一些配置 1、配置账号密码,这样maven就可以访问nexus服务器,传输或下载文件了 在maven安装目录下的settings.xml文件中配置(如D:\maven\apache-maven-3.3.9\conf\settings.xml)
servers节点下配置nexus网站的用户名密码
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<!--测试版-->
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
2、配置POM项目中pom.xml文件,使项目发布到私服
project节点下配置如下,其中仓库对应的id要和上面server中配置的id一致,url就是nexus网站中Repositories下releases和snapshots
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Release</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
要注意当前项目version的配置,如果想发布到releases仓库,就要配置成“版本号”或“版本号-release”;如果发布到snapshots仓库,就配置成“版本号-snapshot”,不区分大小写
执行maven的发布命令后就会发布到指定仓库 我用的是IDEA,所有直接双击执行maven deploy命令即可 ,注意的是IDEA如果不设置会自己下载一套maven,这需要修改maven路径
四、从私服获取jar包
1、配置镜像,对指定路径进行拦截,默认maven访问中央,拦截后改为访问私服
在maven安装目录下的settings.xml文件中配置(如D:\maven\apache-maven-3.3.9\conf\settings.xml)
mirrors节点下配置
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
url配置成http://localhost:8081/nexus/content/groups/public/,这样获取jar包可以根据配置顺序优先级选择下载
2、settings.xml中配置profile,maven自定义配置,配置后如果使用需要激活
profiles节点下配置,注意profile下的id要和上面镜像的id一致,respositories和pluginRepositories要使用镜像中配置的
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
3、settings.xml激活profile,settings节点下配置
<!--注意这个activeProfile标签中间的名字是上边的profile中的id标签中的名字-->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
加了一些补充,对下文做了部分修改。 摘自:https://www.cnblogs.com/hujiapeng/p/7127213.html
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有