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文件中;
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
<modelVersion>4.0.0 </modelVersion>
-
<!-- 略 -->
-
<modules>
-
<!-- 略 -->
-
</modules>
-
-
<dependencyManagement>
-
<!-- 略 -->
-
</dependencyManagement>
-
-
<!-- Environment Settings -->
-
<distributionManagement>
-
<repository>
-
<id>nexus-releases </id>
-
<name>Releases Repository of XXX </name>
-
<url>http://your-server/nexus/content/repositories/releases/ </url>
-
</repository>
-
<snapshotRepository>
-
<id>nexus-snapshots </id>
-
<name>Snapshots Repository of XXX </name>
-
<url>http://your-server/nexus/content/repositories/snapshots </url>
-
</snapshotRepository>
-
</distributionManagement>
-
<repositories>
-
<repository>
-
<id>nexus-public </id>
-
<name>Public Repository of XXX </name>
-
<url>http://your-server/nexus/content/groups/public/ </url>
-
<releases>
-
<enabled>true </enabled>
-
</releases>
-
<snapshots>
-
<enabled>true </enabled>
-
</snapshots>
-
</repository>
-
</repositories>
-
<!-- Environment Settings -->
-
</project>
该配置完成了java构件的下载仓库(repostories)和发布仓库(distributionManagement)。
值得注意的是,发布构建一般需要帐号和密码,需要配置在settings.xml文件中,在后面会提到。
b、配置在Maven的配置中,有两处:(1)Maven程序的conf目录下的settings.xml中,作用于全局用户;(2)在用户目录的.m2文件夹(隐藏文件)下的settings.xml中,作用于当前用户。配置文件和方法如下:
-
"1.0" encoding="UTF-8" xml version=
-
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
-
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation= "http://maven.apache.org/SETTINGS/1.0.0
-
http://maven.apache.org/xsd/settings-1.0.0.xsd">
-
<mirrors>
-
<mirror>
-
<id>nexus-public </id>
-
<name>Nexus Repository of XXX </name>
-
<url>http://your-server/nexus/content/groups/public/ </url>
-
<mirrorOf>central </mirrorOf>
-
</mirror>
-
</mirrors>
-
<servers>
-
<!-- 略 -->
-
</servers>
-
</settings>
该配置实际上实现了中央库的镜像,因为在Pom文件不做任何配置的情况下,默认是使用id为central的Maven中央库进行配置的。
注意,该配置只取代了pom中的下载仓库。
5、配置构件发布的帐号与密码
在settings.xml中配置,这个文件在第4点中有提到,配置如下:
-
"1.0" encoding="UTF-8" xml version=
-
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
-
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation= "http://maven.apache.org/SETTINGS/1.0.0
-
http://maven.apache.org/xsd/settings-1.0.0.xsd">
-
<servers>
-
<server>
-
<id>nexus-releases </id>
-
<username>developer </username>
-
<password>123456 </password>
-
</server>
-
<server>
-
<id>nexus-snapshots </id>
-
<username>developer </username>
-
<password>123456 </password>
-
</server>
-
</servers>
-
</settings>
注意:id必须与Pom文件中配置的id一致。