Nexus 是Maven仓库管理器,如果你使用Maven,你可以从Maven中央仓库下载所需要的构件(artifact),但这通常不是一个好的做法,你应该在本地架设一个Maven仓库服务器,在代理远程仓库的同时维护本地仓库,以节省带宽和时间,Nexus就可以满足这样的需要。此外,他还提供了强大的仓库管理功能,构件搜索功能,它基于REST,友好的UI是一个extjs的REST客户端,它占用较少的内存,基于简单文件系统而非数据库。这些优点使其日趋成为最流行的Maven仓库管理器。
下载安装
从网nexus网站http://www.sonatype.org/nexus/下载最新的nexus.war包。将其放在tomcat的webapps目录下,启动tomcat,访问地址:http://localhost:8080/nexus
nexus配置
以admin/admin123进行登录,进入Repository菜单,修改 Apache Snapshots,Codehaus Snapshots,Maven Central的Download Remote indexs 为true.并右击每一个仓库的 repair Index ,进行更新index 并把所有的proxy类型的仓库添加到public repository中去。
配置Maven使用Nexus
在$user_home/.m2/目录下新建settings.xml,文件内容如下:
<settings> <!-- <mirrors> <mirror> <id>nexus-public</id> <mirrorOf>public</mirrorOf> <url>http://localhost:8080/nexus/content/groups/public</url> </mirror> </mirrors> --> <profiles> <profile> <id>development</id> <repositories> <repository> <id>central</id> <url>http://localhost:8080/nexus/content/groups/public</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://localhost:8080/nexus/content/groups/public</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> <profile> <activeProfiles> <activeProfile>development</activeProfile> </activeProfiles> <!--通过maven来部署构件时需要加上servers这段配置--> <servers> <server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers> </settings>
通过maven来部署构件
在需要部署的构件项目的pom.xml中加上如下内容:
<project> ... <distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://localhost:8080/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://localhost:8080/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement> ... </project>
在项目目录中执行mvn deploy ,你会看到maven将项目构件部署到Nexus中,浏览Nexus对应的仓库,就可以看到刚才部署的构件。当其他人构建其项目时,Maven就会从Nexus寻找依赖并下载。