读书人

Maven的应用及Nexus私服配置(二)

发布时间: 2012-07-02 17:46:22 作者: rapoo

Maven的使用及Nexus私服配置(二)

? ? 上一篇文件介绍了maven eclipse插件的安装,本文将详细介绍nexus私服的搭建方法。

?

1.访问http://www.sonatype.org/nexus/下载最新的nexus压缩文件,将文件解压到指定目录。

2.找到解压目录的bin文件夹,从命令窗口进入该文件夹使用 nexus install命令将该nexus安装为系统服务,这样系统开机时便会启动nexus。安装完后,使用nexus start启动nexus服务。

3.使用浏览器访问http://www.sonatype.org/nexus/,即可看初始页面,点击右上角的log in使用admin/admin123登录系统。

4.登录后点击左侧菜单Repositories,可看到如下界面:

Maven的应用及Nexus私服配置(二)

右侧上部窗口是由nexus做代理的仓库,其中central为maven主仓库,大部分开源项目的jar包都在此项中管理。点击central(红色标记)后下面会出现相应的配置,点击configuration选项卡后有个Download Remote Indexes的选项,默认是false要改为true。此项是告诉nexus是否需要下载远程仓库中的索引文件,点击save后nexus会在后台自动开启一个线程进行下载。另外几个type为proxy的仓库也同样修改其配置(Apache 和 Codehaus)。

等待一段时间后就可以使用Browse Index选项卡来查看下载的索引了,里面有很多的开源项目。

? ? ? 到此nexus私服基本搭建完毕,后面就是在maven中如何使用私服了。

5.修改settings.xml文件,以便让maven工具和m2eclipse插件使用,修改完后的内容如下:

?

<?xml version="1.0" encoding="UTF-8"?><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">    <!-- 本地仓库地址,配置成nexus对应的目录即可,这样m2eclipse在解析依赖时便会引用该仓库中的jar文件 -->  <localRepository>E:\Program Files\nexus-2.0.4\sonatype-work\nexus\storage\central</localRepository>  <mirrors><!-- 本地仓库代理镜像,配置了使用nexus匹配方式为任意。这样在maven在下载相应的依赖时就会在nexus中寻找,若nexus未从远程仓库中下载该项目jar文件等则nexus会下载到自己的仓库中,并提供给相应的项目使用。--><mirror>      <id>Nexus</id>      <name>Nexus Public Mirror</name>      <url>http://localhost:8081/nexus/content/groups/public</url>      <mirrorOf>*</mirrorOf>    </mirror>  </mirrors>  <profiles><profile>      <id>nexus</id>      <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>  </profiles>  <activeProfiles>    <activeProfile>nexus</activeProfile>  </activeProfiles></settings>
?

6.修改完settings.xml后需要在m2eclipse插件中更新配置,界面如下:

Maven的应用及Nexus私服配置(二)

选择刚刚修改过的settings.xml文件,点击update settings后,local repository便会相应的改变。

?

7.在eclipse中重新打开maven repositories视图,界面如下:

Maven的应用及Nexus私服配置(二)

右键点击Nexus 选择 rebuild索引,这时索引便能很快创建完成,因为是直接下载本地nexus中的索引文件。

?

8.重新打开pom文件视图,点击增加dependency 输入相应的项目名即可进行正常索引了。

Maven的应用及Nexus私服配置(二)

?

OK,至此maven已可正常使用nexus私服了,索引相当快速,准备在以后的项目中多试验下。希望大家能多提供些团队使用maven的经验,感激不尽啊。

读书人网 >开源软件

热点推荐