本篇介绍安装Maven和Nexus。
1、下载安装Maven。
虽然Eclipse内嵌的maven,但是如果想配置个性的Maven还是需要安装一个完整版。
下载地址:http://maven.apache.org/download.html
下载最新版本的Maven。
解压到某个目录下即可。后面用${MAVEN_HOME}代替这个目录。
2、下载Nexus。
下载地址:http://www.sonatype.org/nexus/go
nexus有几个发布形式,我选择war distrubution,应为比较好配置。也可以用其他形式配置成系统服务。
3、安装Nexus。
将下载的nexus-x.x.x.war拷贝到WEB服务器里,我用Tomcat,所以拷贝到Tomcat的webapps下。
重命名为nexus.war。
启动Tomcat,浏览http://localhost:8080/nexus,显示nexus首页就对。
4、配置Nexus。
英文配置文档可以参考:http://www.sonatype.com/books/nexus-book/reference/
1)修改管理员密码。
管理员默认登录名和密码是:admin/admin123
登陆路后,选在左侧菜单Security-->Change Password
2)设置SMTP
nexus可以发送重置密码邮件,如果需要这个功能,就需要配置SMTP。
左侧菜单Administration-->Server-->SMTP Settings。
设置好后可以“Test SMTP settings”
3)允许下载远程索引
Nexus代理3个重要的仓库:Maven Central repository、Apache Snapshot repository、Codehaus Snapshot repository。大多数仓库为了快速搜索都提供索引文件。Nexus默认设置关闭了下载远程索引文件,打开的方法:
左侧菜单Views/Repositories-->Repositories 选择Apache Snapshots 点击Configration选项卡,变更Download Remote Indexes为True。

4)设置部署员账号密码。
nexus默认有一个部署权限的账号。deployment/deployment123。
管理员登陆,左侧菜单Security-->Users 右键点击deployment用户,选择Set Password

5、配置Maven
打开${MAVEN_HOME}/conf/settings.xml
1)去掉localRepository的注释,编辑本地仓库的地址。

2)添加如下配置
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<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>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
6、配置Eclipse的Maven。
Eclipse菜单,Window-->Preferences。打开左侧Maven项目:

点击Add按钮,选中${MAVEN_HOME}目录。

点确定按钮。结果如下图:

再选中User Settings,如下设置:

点击Update Settings按钮和Reindex按钮。
Eclipse会自己工作一段时间,之后就可以使用了。
关于nexus其他操作可以参考网上的使用手册,比如增加自定义的仓库,设置仓库组,设置计划任务等。
本文详细介绍了如何安装和配置Maven及Nexus。包括Maven的下载安装、Nexus的部署配置步骤,如修改管理员密码、设置SMTP、允许下载远程索引等。同时,还提供了Maven配置文件settings.xml的示例,以及如何在Eclipse中配置Maven。
781

被折叠的 条评论
为什么被折叠?



