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文件中;

  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. <dependencyManagement>
  9. <!-- 略 -->
  10. </dependencyManagement>
  11. <!-- Environment Settings -->
  12. <distributionManagement>
  13. <repository>
  14. <id>nexus-releases </id>
  15. <name>Releases Repository of XXX </name>
  16. <url>http://your-server/nexus/content/repositories/releases/ </url>
  17. </repository>
  18. <snapshotRepository>
  19. <id>nexus-snapshots </id>
  20. <name>Snapshots Repository of XXX </name>
  21. <url>http://your-server/nexus/content/repositories/snapshots </url>
  22. </snapshotRepository>
  23. </distributionManagement>
  24. <repositories>
  25. <repository>
  26. <id>nexus-public </id>
  27. <name>Public Repository of XXX </name>
  28. <url>http://your-server/nexus/content/groups/public/ </url>
  29. <releases>
  30. <enabled>true </enabled>
  31. </releases>
  32. <snapshots>
  33. <enabled>true </enabled>
  34. </snapshots>
  35. </repository>
  36. </repositories>
  37. <!-- Environment Settings -->
  38. </project>

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

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

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

  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点中有提到,配置如下:

  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一致。

猜你喜欢

转载自blog.csdn.net/u010598111/article/details/80859575
今日推荐