本文使用MyEclipse2014、maven3.3.9以及nexus2.11.4环境,讲述maven配置release和snapshots版本配置并使用MyEclipse发布一个snapshots版本到nexus本地仓库。
1、配置maven
打开maven安装目录下conf目录下的settings.xml配置文件,在 <servers> </servers>节点中加入自己的nexus用户信息。如
<servers>
<server>
<id>snapshots</id>
<username>test</username>
<password>123123123</password>
</server>
<server>
<id>releases</id>
<username>test</username>
<password>123123123</password>
</server>
</servers>
其中server的id可以从nexus上点击对应的仓库查到,如图为snapshots的Id:
2、添加私有仓库信息
添加私有仓库的配置信息到settings.xml配置文件中,如下将私有仓库的镜像添加到settings中。
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexus-releases</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.246:8089/nexus/content/groups/public</url>
</mirror>
<!--
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
-->
</mirrors>
3、配置MyEclipse
配置MyEclipse使用安装的maven以及修改后的配置文件,如图配置使用外部的maven。
配置使用外部的setting,如图:
4、新建maven测试工程
新建maven工程,关键步骤信息如下:
输入包的信息,如下:
5、配置工程
打开工程,点击pom.xml文件,在其中加入私有服务器的配置信息(注意配置信息的id需要和settings的配置文件以及私有服务器上的配置id一致),如下:
<distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<url>http://192.168.1.246:8089/nexus/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>releases</id>
<url>http://192.168.1.246:8089/nexus/content/repositories/releases</url>
</repository>
</distributionManagement>
加入后的配置如图:
6、发布
点击工程,右键弹出菜单,如图添加配置:
新建一个配置,在Main中选择工程的根目录,然后Goals中输入如下内容并点击run开始发布:
deploy -e
如图:
发布成功后会输出如下信息:
如果此时出错提示配置M2_HOME,可以参考如下博客解决:http://blog.csdn.net/smilefyx/article/details/64440975
发布成功后在nexus中搜索test可以看到发布的jar包: