
私服简介
私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。


我们可以使用专门的 Maven 仓库管理软件来搭建私服,比如:Apache Archiva,Artifactory,Sonatype Nexus。这里我们使用 Sonatype Nexus。
上面这部分转载自博客Nexus安装、使用说明、问题总结,由于使用转载博客的安装无法进行,这里我说明怎么安装
安装nexus
nexus下载地址:https://www.sonatype.com/download-oss-sonatype

解压

进入bin目录

打开cmd窗口,在这个目录下进行安装
启动服务 nexus.exe /run (启动成功后不要关闭命令行窗口)

当看到图中所示界面时,表示启动成功

安装服务 nexus.exe /install (重新使用新的命令行安装,可能出现权限不足,请以管理员身份运行命令行)
怎么打开管理员身份的cmd窗口

安装

启动服务 net start nexus

停止服务 net stop nexus

如果不知道默认端口号是多少,可以进入目录 etc/下,有一个文件nexus-default.properties
当中就有默认端口号

初始登录
3.17版本密码改成随即的了,而且登录时候提示密码在/nexus-data/admin.password里

因为登录后,nexus会删除这个文件,这里我保留了windows的路径

Nexus的使用
从Nexus私服下载资源
找到maven配置文件settings.xml,添加如下配置
- 1)添加镜像配置,将所有访问外网仓库的请求指向私服
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>