Nexus OSS私服仓库的安装和配置以及与Maven整合配置

1、到官网(http://www.sonatype.org/nexus/)下载最新的开源版本,一般有两种,war包和bundle包,明显,war必须放在web容器下,而bundle已经包含了一个Jetty容器,启动就可以运行。

2、默认的监听地址为:http://your-server:8081/nexus

3、Nexus的默认登录帐号为:admin:admin123


4、配置Maven与nexus的连接

a、直接配置在项目的Pom文件中;

[html]  view plain  copy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <!-- 略 -->  
  5.     <modules>  
  6.         <!-- 略 -->  
  7.     </modules>  
  8.   
  9.     <dependencyManagement>  
  10.         <!-- 略 -->  
  11.     </dependencyManagement>  
  12.   
  13.     <!-- Environment Settings -->  
  14.     <distributionManagement>  
  15.         <repository>  
  16.             <id>nexus-releases</id>  
  17.             <name>Releases Repository of XXX</name>  
  18.             <url>http://your-server/nexus/content/repositories/releases/</url>  
  19.         </repository>  
  20.         <snapshotRepository>  
  21.             <id>nexus-snapshots</id>  
  22.             <name>Snapshots Repository of XXX</name>  
  23.             <url>http://your-server/nexus/content/repositories/snapshots</url>  
  24.         </snapshotRepository>  
  25.     </distributionManagement>  
  26.     <repositories>  
  27.         <repository>  
  28.             <id>nexus-public</id>  
  29.             <name>Public Repository of XXX</name>  
  30.             <url>http://your-server/nexus/content/groups/public/</url>  
  31.             <releases>  
  32.                 <enabled>true</enabled>  
  33.             </releases>  
  34.             <snapshots>  
  35.                 <enabled>true</enabled>  
  36.             </snapshots>  
  37.         </repository>  
  38.     </repositories>  
  39.     <!-- Environment Settings -->  
  40. </project>  

该配置完成了java构件的下载仓库(repostories)和发布仓库(distributionManagement)。

值得注意的是,发布构建一般需要帐号和密码,需要配置在settings.xml文件中,在后面会提到。

b、配置在Maven的配置中,有两处:(1)Maven程序的conf目录下的settings.xml中,作用于全局用户;(2)在用户目录的.m2文件夹(隐藏文件)下的settings.xml中,作用于当前用户。配置文件和方法如下:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  
  3.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.         xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0  
  5.                       http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  6.         <mirrors>  
  7.                 <mirror>  
  8.                         <id>nexus-public</id>  
  9.                         <name>Nexus Repository of XXX</name>  
  10.                         <url>http://your-server/nexus/content/groups/public/</url>  
  11.                         <mirrorOf>central</mirrorOf>  
  12.                 </mirror>  
  13.         </mirrors>  
  14.         <servers>  
  15.                 <!-- 略 -->  
  16.         </servers>  
  17. </settings>  

该配置实际上实现了中央库的镜像,因为在Pom文件不做任何配置的情况下,默认是使用id为central的Maven中央库进行配置的。

注意,该配置只取代了pom中的下载仓库。

5、配置构件发布的帐号与密码

在settings.xml中配置,这个文件在第4点中有提到,配置如下:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  
  3.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.         xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0  
  5.                       http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  6.         <servers>  
  7.                 <server>  
  8.                         <id>nexus-releases</id>  
  9.                         <username>developer</username>  
  10.                         <password>123456</password>  
  11.                 </server>  
  12.                 <server>  
  13.                         <id>nexus-snapshots</id>  
  14.                         <username>developer</username>  
  15.                         <password>123456</password>  
  16.                 </server>  
  17.         </servers>  
  18. </settings>  

注意:id必须与Pom文件中配置的id一致。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值