您的位置:首页 > 其它

maven 之 nexus 私服搭建学习总结

2015-08-01 16:53 501 查看
自己今天学习的笔记:

1、下载最新 nexus 的网址:

http://www.sonatype.org/nexus/archived/#step2top

2、配置 nexus 的 Java(JDK) 路径:

D:\app\nexus-2.11.1-01-bundle\nexus-2.11.1-01\bin\jsw\conf
路径的 wrapper.conf 文件里,配置如下:

wrapper.java.command=D:/app/Java/jdk1.8.0_45/bin/java


然后执行 :

%nexus_home%\bin\nexus.bat install (安装成windows服务)

%nexus_home%\bin\nexus.bat start (启动)


输入:
http://192.168.199.158:8081/nexus
(注意:ip 可以写 localhost),使用用户名 admin ,密码 admin123,登陆。

3、nexus 的 index 文件解压路径(针对中央仓库而言)

D:\app\nexus-2.11.1-01-bundle\sonatype-work\nexus\indexer\central-ctx


参考资料:

1、许晓斌的博客(专家博客,必须放在第 1 位)

Nexus 入门指南(图文)

http://juvenshun.iteye.com/blog/349534

核心内容部分摘抄:

默认情况下, Maven 依赖于中央仓库,这是为了能让 Maven 开箱即用,但仅仅这么做明显是错误的,这会造成大量的时间及带宽的浪费。既然文章的前面已经介绍了如何安装和配置 Nexus ,现在我们就要配置 Maven 来使用本地的 Nexus ,以节省时间和带宽资源。

我们可以将 Repository 配置到 POM 中,但一般来说这不是很好的做法,原因很简单,你需要为所有的 Maven 项目重复该配置。因此,这里我将 Repository 的配置放到
$user_home/.m2/settings.xml
中。

文章的最后介绍了两种方式部署构件到 nexus 中的方式:1、通过 Nexus 的 UI 部署,2、通过 Maven 部署。

下面整理一下在 maven 中部署的步骤:

(1) 在 pom.xml 文件中声明
<distributionManagement>
节点:

<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Releases Repository</name>
<url>http://192.168.199.158:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshots Repository</name>
<url>http://192.168.199.158:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>


说明:其中的 releases 版本和 snapshots 版本的链接地址可以在 nexus 的 ui 里面查询到。

(2)在 settings.xml 中配置 server ,其中 server 节点的 id 应该和 pom.xml 中节点的 id 一致。

示例:

<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>


然后执行
mvn deploy
命令,就可以将自己写的构件部署到 nexus 私服上面供他人使用了。

控制台输出(截取):

[INFO] --- maven-install-plugin:2.4:install (default-install) @ HessianClient ---
[INFO] Installing /Users/liwei1/gitlab/statistic/HessianClient/target/HessianClient-0.0.1-SNAPSHOT.jar to /Users/liwei1/.m2/repository/com/store59/hessian/client/HessianClient/0.0.1-SNAPSHOT/HessianClient-0.0.1-SNAPSHOT.jar
[INFO] Installing /Users/liwei1/gitlab/statistic/HessianClient/pom.xml to /Users/liwei1/.m2/repository/com/store59/hessian/client/HessianClient/0.0.1-SNAPSHOT/HessianClient-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ HessianClient ---
[INFO] Downloading: http://192.168.199.158:8081/nexus/content/repositories/snapshots/com/store59/hessian/client/HessianClient/0.0.1-SNAPSHOT/maven-metadata.xml [INFO] Uploading: http://192.168.199.158:8081/nexus/content/repositories/snapshots/com/store59/hessian/client/HessianClient/0.0.1-SNAPSHOT/HessianClient-0.0.1-20150801.085006-1.jar [INFO] Uploaded: http://192.168.199.158:8081/nexus/content/repositories/snapshots/com/store59/hessian/client/HessianClient/0.0.1-SNAPSHOT/HessianClient-0.0.1-20150801.085006-1.jar (11 KB at 62.7 KB/sec)
[INFO] Uploading: http://192.168.199.158:8081/nexus/content/repositories/snapshots/com/store59/hessian/client/HessianClient/0.0.1-SNAPSHOT/HessianClient-0.0.1-20150801.085006-1.pom [INFO] Uploaded: http://192.168.199.158:8081/nexus/content/repositories/snapshots/com/store59/hessian/client/HessianClient/0.0.1-SNAPSHOT/HessianClient-0.0.1-20150801.085006-1.pom (3 KB at 62.0 KB/sec)
[INFO] Downloading: http://192.168.199.158:8081/nexus/content/repositories/snapshots/com/store59/hessian/client/HessianClient/maven-metadata.xml [INFO] Uploading: http://192.168.199.158:8081/nexus/content/repositories/snapshots/com/store59/hessian/client/HessianClient/0.0.1-SNAPSHOT/maven-metadata.xml [INFO] Uploaded: http://192.168.199.158:8081/nexus/content/repositories/snapshots/com/store59/hessian/client/HessianClient/0.0.1-SNAPSHOT/maven-metadata.xml (789 B at 13.8 KB/sec)
[INFO] Uploading: http://192.168.199.158:8081/nexus/content/repositories/snapshots/com/store59/hessian/client/HessianClient/maven-metadata.xml [INFO] Uploaded: http://192.168.199.158:8081/nexus/content/repositories/snapshots/com/store59/hessian/client/HessianClient/maven-metadata.xml (299 B at 13.3 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.644 s
[INFO] Finished at: 2015-08-01T16:50:06+08:00
[INFO] Final Memory: 20M/228M
[INFO] ------------------------------------------------------------------------


小知识:maven 是如何知道你要发布的是 release 版本还是 snapshot 版本呢?是根据我们在构件里面声明的
version
来判断的,如果是带有 snapshot 后缀的,就发布到 snapshot 仓库里,其余的 nexus 就认为你要发布到 release 版本库里。

2、菩提树下的杨过

http://www.cnblogs.com/yjmyzz/p/3519373.html

说明:比较简单的入门教程。

3、nexus搭建和手动更新索引心得

网址:

http://www.fwqtg.net/nexus%E6%90%AD%E5%BB%BA%E5%92%8C%E6%89%8B%E5%8A%A8%E6%9B%B4%E6%96%B0%E7%B4%A2%E5%BC%95%E5%BF%83%E5%BE%97.html

说明:从这个网址上,我们可以查询到下载下来的 maven 的 nexus 索引放在哪个目录下。注意:重启服务以后,登陆就会生效。

4、其他参考资料:

http://blog.csdn.net/liujiahan629629/article/details/39272321

http://blog.csdn.net/mtkong/article/details/9377605

http://www.fwqtg.net/nexus%E6%90%AD%E5%BB%BA%E5%92%8C%E6%89%8B%E5%8A%A8%E6%9B%B4%E6%96%B0%E7%B4%A2%E5%BC%95%E5%BF%83%E5%BE%97.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  maven nexus