且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

sonatype nexus 搭建maven服务器二

更新时间:2022-09-27 19:49:13

一、nexus的安装:

1、配置环境变量:

NEXUS_HOME=D:\nexus\nexus-2.3.1-01(nexus-2.3.1-01已上传到51CTO下载中心

Path=%MEXUS_HOME%\bin;......

2、验证环境变量是否配置成功:

cmd>nexus 出现如下界面说明环境变量配置成功。

sonatype nexus 搭建maven服务器二

3、安装服务:

cmd>nexus install

4、启动nexus:

cmd>nexus start

5、访问nexus:

http://localhost:8081/nexus/index.html

登录信息:admin=admin123

看到如下界面,大功告成!!!

sonatype nexus 搭建maven服务器二

二、Maven仓库配置: 


1、maven的默认情况是首先访问“本地仓库”,本地没有直接访问“中间仓库”。

访问中间仓库的配置是在D:\tool\apache-maven-3.0.4\lib\maven-model-builder-3.0.4.jar的pom.xml中。

<repositories> 

 <repository>

  <id>central</id> 

  <name>Central Repository</name> 

  <url>http://repo.maven.apache.org/maven2</url> 

  <layout>default</layout>

  <snapshots> 

   <enabled>false</enabled> 

  </snapshots>  

  </repository> 

</repositories>


2、可以通过配置maven的setting.xml文件的profile,实现首先访问“本地仓库”,本地仓库没有访问“私有Nexus仓库”,“私有Nexus仓库”没有才访问“中间仓库”。

  1. )配置profile:

      <profile>

      <id>nexusProfile</id>

      <repositories>

        <repository>

          <id>nexus</id>

          <name>nexus Repository</name>

          <url>http://localhost:8081/nexus/content/groups/public/</url>

        <!--默认snapshot是关闭的,需要手工开启-->

        <snapshots>

            <enabled>true</enabled>

        </snapshots>

        </repository>

      </repositories>

    </profile>

2.)配置activeProfile(激活profile):

     <activeProfile>nexusProfile</activeProfile>


3、可以通过配置maven的setting.xml文件的mirror,实现首先访问“本地仓库”,本地仓库没有访问“私有Nexus仓库”,“私有Nexus仓库”没有“”访问“中间仓库”。

   <mirror>

      <id>nexusmirror</id>

      <mirrorOf>*</mirrorOf>

      <name>Human Readable Name for this Mirror.</name>

      <url>http://localhost:8081/nexus/content/groups/public/</url>

    </mirror>

注意:只要mirrorOf的工厂(如nexus、central)要访问,都会自动来找镜像mirror,如果mirror无法访问到就不会再去中间工厂访问,使用*表示所有的工厂都使用这个镜像访问,使用*这是推荐的做法。



















本文转自lzf0530377451CTO博客,原文链接: http://blog.51cto.com/8757576/1763346,如需转载请自行联系原作者