Nexus3之在Window中搭建Maven私服
文章目录
- Nexus3之在Window中搭建Maven私服
- 1. 下载
- 2. 安装
- 3. 创建用户及仓库
- 4. maven的setting.xml文件修改
- 5. POM.xml文件修改
1. 下载
官网: https://www.sonatype.com/download-oss-sonatype
下载OSS免费版,如下载版本为:Nexus-3.16.0-latest-win64.zip
2. 安装
- 先将Nexus-3.16.0-latest-win64.zip文件解压到指定目录,如:D:\Nexus-3.16.0目录下
- 将D:\Nexus-3.16.0\nexus-3.16.2-01\bin 添加到环境变量的path路径后面
- 以管理员身份打开cmd窗口,输入下面命令安装
# 注册服务
nexus /install Nexus3 #此命令直接注册到服务中,名称为Nexus3
# 启动服务
net start Nexus3
- 浏览器总输入 http://localhost:8081 进行访问,第一次访问时间稍微有些长
3. 创建用户及仓库
浏览器中打开Nexus图形界面后,输入管理员密码登录,默认账户/密码为 admin/admin123
注意:最新版本的admin会在安装目录下的admin.password文件中,首次登陆后修改admin密码接口,如:3.39.0-01的admin密码位置如下
Your admin user password is located in E:\warehouse\nexus-3.39.0-01\sonatype-work\nexus3\admin.password on the server.
- 创建一个用户,比如 yuan/yuan123
- 配置一个代理(proxy)仓库,如使用阿里云的maven仓库,URL: http://maven.aliyun.com/nexus/content/groups/public/
- 创建两个hosted(宿主)类型的仓库
#名称为yuan-releases的hosted仓库
http://localhost:8081/repository/yuan-releases/
#名称yuan-sanpshots的hosted仓库
http://localhost:8081/repository/yuan-snapshots/
- 创建一个group类型的仓库
#名称为yuan-public的group类型仓库
http://localhost:8081/repository/yuan-public/
- 将yuan-releases 与 yuan-snapshots 添加到仓库组 yuan-public中
4. maven的setting.xml文件修改
- server配置
<servers> <!--发布版--><server><id>yuan-releases</id><username>yuan</username><password>yuan123</password></server><!--快照版--><server><id>yuan-snapshots</id><username>yuan</username><password>yuan123</password></server></servers>
- mirrors配置
<mirrors> <!--使用阿里云的镜像仓库--><mirror><id>nexus-aliyun</id><name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url><mirrorOf>central</mirrorOf></mirror> <!--私服地址--><mirror><id>nexus-yuan</id><mirrorOf>*</mirrorOf><name>Nexus yuan</name><url>http://localhost:8081/repository/yuan-public/</url></mirror></mirrors>
- profiles编写
<profiles><!--使用指定的jdk版本--><profile><id>jdk8</id><activation><activeByDefault>true</activeByDefault><jdk>1.8</jdk></activation><properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></properties><!--私服库配置--><repositories><repository><id>nexus-yuan</id><name>nexus yuan group</name><url>http://localhost:8081/repository/yuan-public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><!--私服插件配置--><pluginRepositories><pluginRepository><id>nexus-yuan</id><name>nexus yuan group</name><url>http://localhost:8081/repository/yuan-public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository></pluginRepositories></profile></profiles><!--激活名称为jdk8的porfile--><activeProfiles><activeProfile>jdk8</activeProfile></activeProfiles>
5. POM.xml文件修改
一般将私服配置到父工程的pom.xml文件中
- 在pom.文件中添加下面内容
<distributionManagement><!--发布版仓库--><repository><!--这里的id配置一定要与settin.xml文件中server配置中的id一致,否则可能出现405错误--><id>yuan-releases</id><name>nexus yuan group</name><url>http://localhost:8081/repository/yuan-releases/</url></repository><!--快照版仓库--><snapshotRepository><!--这里的id配置一定要与settin.xml文件中server配置中的id一致--><id>yuan-snapshots</id><name>nexus yuan group</name><url>http://localhost:8081/repository/yuan-snapshots/</url></snapshotRepository></distributionManagement>
- 完成后,可在idea中执行maven的install命令进行安装
- install命令成功后,可执行deploy命令将jar发布的maven私服库中。