Nexus和Maven安装配置

本文详细介绍如何搭建Maven环境并配置Nexus作为私有仓库,包括Maven的安装配置、Nexus的下载启动及配置过程,同时讲解了如何通过settings.xml和pom.xml文件配置Maven项目使用私服。

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/nexusstart

关闭:/usr/local/jenkins/nexus-2.12/bin/nexusstop

访问:http://192.168.1.135:8081/nexus

默认端口8081,默认用户/密码:admin/admin123

3、配置Nexus

将列表中所有Type为proxy 的项目的 Configuration 中的 Download Remote Indexes 设置为True

将Releases仓库的Deployment Policy设置为 AllowReDeploy 

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


打造自己的maven内部库 Nexus是Sonatype推出的强大Maven仓库管理器产品。有以下优点: 代理远程仓库。配置Nexus代理中央仓库,其它任何公开的Maven仓库,将你组织内部的Maven配置指向Nexus,这样所有构件都将从Nexus下载,如果Nexus没有你要的构件,它会自动先去外部仓库下载到本地,仅一次。 本地宿主仓库。Nexus可以在服务器上建立本地的宿主仓库,你可以往这个仓库里提交任意的Maven规范构件,包括不能从公开仓库下载到的构件,或者你组织内部产生的构件。 仓库组。有了仓库组,你就能将很多仓库聚合起来,对外公开一个统一的接口提供构件服务。 构件搜索。Nexus能下载远程的仓库索引,并在本地构件自己的仓库索引,有了该索引,你就能很快速方便的搜索任何你感兴趣的构件。 事情RSS源。Nexus服务器上发生的几乎任何事情,你都能用RSS监视,方便管理。 ReleaseSnapshots区分。配置Nexus提供Release构件服务或者Snapshots服务,能更清晰的管理构件。 路由。Nexus的路由能够管理为特定的请求提供特定的仓库。加入你在一个组中配置了很多仓库,一条路由能够极大提高某些特定请求的响应速度。 上传构件。使用Nexus你能很方便的在web界面上上传一些特殊的构件至仓库。 高用户体验的UI。使用AJAXREST技术开发的Nexus,在界面上为提供了很舒适的用户体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BUG弄潮儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值