Maven的仓库只有两大类:1.本地仓库 2.远程仓库
远程仓库中分成了3种:
- 中央仓库
- 私服
- 其它公共库
私服:是一种特殊的远程仓库,架设在局域网内。私服代理广域网上的远程仓库,供局域网内的Maven用户使用。当Maven需要下载构件的时候,它从私服请求,如果私服上不存在该构件,则从外部的远程仓库下载,缓存在私服上之后,再为Maven的下载请求提供服务。
安装
Nexus下载地址
下载完成后,将 bin 目录配置到环境变量,通过cmd命令打开docs窗口,输入nexus命令:
Usage: nexus { console : start : stop : restart : install : uninstall }
使用之前通过nexus install命令安装私服,然后通过nexus start启动私服,nexus私服有自己内置的服务器,默认的访问端口号是8081,访问地址是:http://localhost:8081/nexus/
起步
点击右上角的log in输入admin/admin123登陆私服,点击Views/Repositories下的Repositories进入如下页面:
创建代码仓库
- group(仓库组类型):又叫组仓库,用于方便开发人员自己设定的仓库,能把多个仓库合成一个仓库来使用
- hosted(宿主类型):是宿主机的意思,内部项目的发布仓库(一般分为releases发布版以及snapshots快照)
- proxy(代理类型):proxy就是代理的意思,代理中央Maven仓库,当PC访问中央库的时候,先通过Proxy下载到Nexus仓库,然后再从Nexus仓库下载到PC本地。
- virtual(虚拟类型):虚拟仓库(这个基本用不到,重点关注上面三个仓库的使用)
上传到nexus私服
修改Maven的settings.xml文件,加入认证机制
<server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server>
修改工程的pom文件
<distributionManagement><repository><id>nexus-releases</id><url>http://${maven.server}/repository/mvn-releases/</url></repository><snapshotRepository><id>nexus-snapshots</id><url>http://${maven.server}/repository/mvn-snapshots/</url></snapshotRepository>
</distributionManagement>
注: pom文件中的id要跟settings.xml文件中的id一定要对应上
指定nexus私服
<!--将nexus私服配置为远程仓库-->
<repositories><repository><id>nexus</id><url>http://${maven.server}/repository/mvn-public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository>
</repositories>
转载:Nexus私服详细讲解