4. 配置
选择左边 Views/Repositories 菜单下的 Repositories,可以看到一些预设的仓库,我们会用到的一般只有 Public Repositories 和 3rd party , Public Repositories 为公共仓库,3rd party 为第三方仓库,可以上传第三方的 Jar (当然也可以是自己封装的 Jar);
5. Maven 配置
如果此时本地没有配置Maven 环境变量,请参考: 本地Maven 环境配置
copy settings.xml -> C:\Users\xxx\.m2
6. Maven settings.xml 文件配置
接下来需要修改 Maven 的配置文件settings.xml,整合 Nexus;
1. 找到 <servers> 标签,添加 Nexus 默认认证信息:
<server> <id>my-nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>my-nexus-snapshot</id> <username>admin</username> <password>admin123</password> </server>
如图所示:
2. 找到 <mirrors> 标签,添加镜像:
<mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/nexus/content/groups/public/</url> </mirror>
如图所示:
3. 找到 <profiles> 标签,添加仓库信息:
<profile> <id>nexus</id> <!--Enable snapshots for the built in central repo to direct --> <!--all requests to nexus via the mirror --> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile>
如图所示:
4. 激活仓库:
<activeProfiles> <!--make the profile active all the time --> <activeProfile>nexus</activeProfile> </activeProfiles>
如图所示:
注意:
1. 在配置settings.xml 文件的过程中,请注意xml 标签段落和层次格式;
2. 建议在标签注释下添加新标签内容;
配置完成后保存,并重启 nexus 服务即可;
5. 重启nexus 服务
nexus restart
如图所示: