1、下载maven私服工具
可以百度搜索 或 从百度网盘中下载
这里已经将工具上传到百度网盘,下载链接:
链接:https://pan.baidu.com/s/1eSh_TegWUFsEBlv92PWYiw
提取码:cobz
下载 windows系统安装包,即 nexus-2.12.0-01-bundle.zip 文件
2、安装私服
首先,先将 nexus-2.12.0-01-bundle.zip 文件解压到某个目录(目录不含空格)
解压后发现有两个目录,分别是:nexus-2.12.0-01 和 sonatype-work
nexus-2.12.0-01 目录:私服安装及运行时需要用到相关文件
私服仓库:在 sonatype-work\nexus 目录下面,由于还没有创建仓库,所以该目录下面没有任何目录或文件。
安装私服:将 私服安装到 windows 服务项中
使用 windows 命令行(以管理员身份运行),进入到 nexus-2.12.0-01\bin 目录,执行 nexus.bat install 安装私服
此时windows服务项中,可以找到服务名 为 nexus 的服务。说明私服安装成功。
3、启动私服服务器
注意私服服务器端口占用问题:服务器默认使用的是 8081 端口。(在 nexus-2.12.0-01\conf\nexus.properties 文件中可以看到相关信息 )
在 windows 服务项中,找到服务名 为 nexus 的服务,并启动该服务。
点击 “启动” 服务。
或者服务项中,右键启动。
私服服务器启动成功:
4、访问私服服务器(默认端口为 8081)
打开电脑中的浏览器:
输入地址 http://localhost:8081/nexus/ 或者 http://192.168.1.106:8081/nexus/
浏览器自动跳转到 http://localhost:8081/nexus/#welcome 或者 http://192.168.1.106:8081/nexus/#welcome
这里以localhost地址为例:
登录服务器:默认账号及密码为 admin / admin123
登录成功:右上角会显示登录账号信息、左侧菜单可看到 Views/Repositories 选项。
5、查看仓库
左侧菜单可看到 Views/Repositories 选项, 点击 Repositories 查看仓库。
在私服安装目录 sonatype-work\nexus\storage 目录下,可以找到对应的仓库目录
6、上传 jar 包到私服
- 配置maven环境,修改 settings 文件,配置连接私服的用户名和密码
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
releases 连接发布版本项目仓库
snapshots 连接测试版本项目仓库
- 配置 (工程或模块的)pom.xml 文件
配置私服仓库的地址,本公司的自己的 jar 包会上传到私服的宿主仓库,如果工程的版本为 release 则上传到私服的 release 仓库,如果版本为 snapshot 则上传到私服的 snapshot 仓库,这里演示配置成localhost即可,如果是是公司中安装的私服地址应该是localhost替换成私服ip地址
在工程或模块的 pom.xml 文件中,添加如下代码:
<distributionManagement>
<repository>
<id>releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
- 测试
- 配置maven环境,修改 settings 文件,配置配置私服的仓库
<profile>
<!--profile 的 id-->
<id>dev</id>
<repositories>
<repository>
<!--仓库 id,repositories 可以配置多个仓库,保证 id 不重复-->
<id>nexus</id>
<!--仓库地址,即 nexus 仓库组的地址-->
<url>http://localhost:8081/nexus/content/groups/public/</url>
<!--是否下载 releases 构件-->
<releases>
<enabled>true</enabled>
</releases>
<!--是否下载 snapshots 构件-->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!-- 插件仓库,maven 的运行依赖插件,也需要从私服下载插件 -->
<pluginRepository>
<!-- 插件仓库的 id 不允许重复,如果重复后边配置会覆盖前边 -->
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</pluginRepository>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
-
测试从私服下载 jar 包