继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Nexus和Maven安装配置

ajax入门学习视频
关注TA
已关注
手记 266
粉丝 80
获赞 597

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
将Releases仓库的Deployment Policy设置为 Allow ReDeploy 

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

填写完必选字段,点击Upload Artifact(s)按钮即可。

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>

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP