使用Nexus搭建maven私服二三事

一:为啥要搭建私服

原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找一台有外网权限的机器,搭建nexus私服,然后开发人员连到这台私服上,这样的话就可以通过这台搭建了nexus私服的电脑访问maven的远程仓库

二:私服部署结构

三:安装私服

下载Nexus, 下载地址:http://www.sonatype.org/nexus/archived/

(博主这里没下载最新的而是下的:下载:nexus-2.12.0-01-bundle.zip)

解压nexus-2.12.0-01-bundle.zip,本教程将它解压在F盘,进入bin目录:

cmd进入bin目录,执行nexus.bat install

(插一句:如果要卸载Nexus,只需要cmd进入nexus的bin目录,执行:nexus.bat uninstall)

四:运行Nexus

方法1:

cmd进入bin目录,执行nexus.bat start

方法2:

直接启动nexus服务

查看nexus的配置文件conf/nexus.properties

默认用户名和密码 :admin/admin123

五:仓库类型

1、hosted:宿主仓库,自己项目的jar要放到hosted类型的仓库中。

2、proxy:代理仓库,代理中央仓库

3、virtual:虚拟仓库,存储了maven1的构件,一般不用。

4、group:仓库组,将一些仓库组成一个组,自己项目连接仓库组去下载jar包。平常开发中都去连接仓库组,仓库组中包括:hosted、proxy等。。

六:使用Nexus

6.1: 在nexus搜索jar包,即在Nexus中加入jar包索引

  方法1:联网下载

  

  方法2:手动下载索引

  

  从网上下载:indexer-cli-5.1.0.jar

  

  

  将这三者放在一个文件夹,cmd执行:java -jar indexer-cli-5.1.0.jar -u nexus-maven-repository-index.gz -d indexer

  就会生成索引目录:

  

  and then:

  

七:将项目发布到私服上:

1、在自己电脑的maven的setting.xml中配置

<server>

          releases对应nexus的仓库名称

      <id>releases</id>

      <username>admin(用户名)</username>

      <password>admin123(密码)</password>

    </server>

        <server>

                 snapshots对应nexus的仓库名称

      <id>snapshots</id>

      <username>admin(用户名)</username>

      <password>admin123(密码)</password>

    </server>

2、配置项目pom.xml

<distributionManagement>

    <repository>

         <id>releases</id>

   <url>http://localhost:8081/nexus/content/repositories/releases/</url>

    </repository>

    <snapshotRepository>

         <id>snapshots</id>

  <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>

    </snapshotRepository>

  </distributionManagement>

 注意:pom.xml这里<id> 和 settings.xml 配置 <id> 对应!(端口8081是我自己设置的自己的端口==。)

3、准备将自己工程的jar发布到nexus私服中。

当你的工程版本是releases会发布到私服的releases仓库

当你的工程版本是snapshots会发布到私服的snapshots仓库

执行deploy

八:从私服上下载jar包

8.1:配置仓库组

仓库组地址:http://localhost:8081/nexus/content/groups/public/

8.2:配置镜像

镜像地址为nexus仓库组的地址 http://localhost:8081/nexus/content/groups/public/

然后在setting.xml配置镜像

<mirror>

          <!--镜像id,mirrors中可以配置多个镜像,但是要保证id不重复-->

      <id>nexus</id>

          <!--mirrorOf 指定仓库id,仓库组包括了id为 releases、snapshots、thirdparty 、central 的仓库,可以配置具体的id,如果镜像所有的仓库则设置为*-->

      <mirrorOf>*</mirrorOf>

          <!--镜像地址-->

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

    </mirror>

 本地项目不连中央仓库,连接镜像(相当于连接私服)

-------------------------------------------------------------------------------------------------------------

end:

 

 

 

       

 

posted @ 2017-07-28 21:14  Lucia557  阅读(428)  评论(0编辑  收藏  举报