Nexus和Maven安装配置

本文详细介绍如何通过Maven和Nexus搭建私有仓库,并配置使用私服,包括Maven和Nexus的安装、配置及私服的使用方法。
1、下载安装Maven
wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
配置MAVEN_HOME
vi /home/jenkins/.bash_profile
MAVEN_HOME=/usr/local/jenkins/apache-maven-3.5.0
export PATH=$PATH:$MAVEN_HOME/bin
2、下载Nexus
http://www.sonatype.org/nexus/archived/#step2top
wget http://download.sonatype.com/nexus/oss/nexus-2.14.4-03-bundle.tar.gz
tar -zxvf nexus-2.14.4-03-bundle.tar.gz
启动:/usr/local/jenkins/nexus-2.12/bin/nexus start
关闭:/usr/local/jenkins/nexus-2.12/bin/nexus stop
访问:http://192.168.1.135:8081/nexus
默认端口8081,默认用户/密码:admin/admin123
3、配置Nexus
将列表中所有Type为proxy 的项目的 Configuration 中的 Download Remote Indexes 设置为True

[img]http://dl2.iteye.com/upload/attachment/0128/7832/79de19f4-d71d-3a94-8ec1-811f3733d00c.png[/img]

将Releases仓库的Deployment Policy设置为 Allow ReDeploy

[img]http://dl2.iteye.com/upload/attachment/0128/7834/80164401-6979-3313-b3f6-d315bb73d61c.png[/img]

当然我们也避免不了会使用到一些第三方的 jar ,而这些jar包也不存在于互联网上的maven中央仓库中,这时我们可以手工添加jar 到我们的私服中。
添加第三方 jar 如下:

[img]http://dl2.iteye.com/upload/attachment/0128/7836/8f8d2f19-9b63-3273-8698-10f7c68c8f52.png[/img]

填写完必选字段,点击Upload Artifact(s)按钮即可。
如果需要删除的话,如下:


[img]http://dl2.iteye.com/upload/attachment/0128/7838/5df5ed89-7744-306d-8125-fd16d33d1e57.png[/img]

4、使用私服配置
配置发布jar到自己的私服
修改Maven的配置文件settings.xml
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
修改工程的pom.xml中添加
<distributionManagement>
<repository>
<!--这个ID需要与你的release仓库的settings.xml Repository ID一致 -->
<id>releases</id>
<url>http://192.168.1.135:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<!--这个ID需要与你的snapshots仓库的settings.xml Repository ID一致 -->
<id>snapshots</id>
<url>http://192.168.1.135:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

配置使用私有maven库(即自己的私服http://192.168.1.135:8081/nexus/):
在项目的pom.xml中配置Nexus私服,这样的配置只对当前的Maven项目有效。
<!--配置jar包使用私有maven库-->
<repositories>
<repository>
<id>public</id>
<name>Team Maven Repository</name>
<url>http://172.18.19.157:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!--配置插件使用私有maven库-->
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>nexus</name>
<url>http://172.18.19.157:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
在Maven的settings.xml中配置profile元素,这样就能让本机所有的Maven项目都使用自己的Maven私服。
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://192.168.1.135:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local-nexus</id>
<url>http://192.168.1.135:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>

[img]http://dl2.iteye.com/upload/attachment/0128/7830/8053c7d0-e81b-317d-a532-f622ed359fb0.jpg[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值