Nexus build Maven central repository PW

I. Overview

  1, Overview

     The project is now basically use Maven to manage the project, so that the company set up a PW content is very necessary, and this way you can manage internal company use the JAR package, you can also manage third-party JAR to, every time so as not to be downloaded from the external network of warehouses. PW has two software built Nexus and artifactory, both have their advantages. This article about the configuration of Nexus. Nexus is a relatively popular PW.

  2, Nexus introduction

       Nexus is a powerful Maven repository manager, which greatly simplifies maintenance and access to external warehouse of their own internal warehouse. You can only use Nexus in one place will be able to completely control access and deployment in your warehouse maintained by each of the Artifact. Nexus is a set of "out of the box" system does not require a database, it uses the file system to organize the data Lucene added. Nexus using ExtJS to develop interfaces to provide a complete REST APIs, through the use of integrated Eclipse m2eclipse and use Restlet. Nexus supports WebDAV and LDAP authentication security.

  Download Nexus is: http: //www.sonatype.org/nexus/go/ to the official website to download ZIP compressed package down to, after extracting found two folders, one is the nexus-2.11.0- 02, and the other is sonatype-work; the first folder contains the files needed to run the Nexus, Nexus is necessary to run; the second folder directory contains the Nexus generated configuration files, log files, repository files, when the time required to back up the Nexus, this directory is the default backup file.

  

Second, prepare the environment

  1, apache-maven-3.2.5 Baidu network disk Download: https: //pan.baidu.com/s/1Rhglh4_RPgT79pXObQ2vZQ extraction code: a6h6 

  About maven please refer to my other article: https: //www.cnblogs.com/liandy001/p/11287278.html

  2, nexus-2.11.4-01-bundle Baidu network disk Download: https: //pan.baidu.com/s/1ZCyVb-Zc5RytvG9tFv5F2Q extraction code: h3d0

  3, JDK1.8 64 bit Baidu network disk Download: https: //pan.baidu.com/s/1lI6BLbWK7DslmIjI_z81Pg extraction code: knuz

   

Three, Nexus environment configuration

  1, modify the system variables

  In the system variable Path added value (D: \ DevelopTools \ nexus-2.11.4-01-bundle \ nexus-2.11.4-01 \ bin; (subject to the actual installation directory))

  

 

  2, corresponding to the configuration of the JDK Nexus

  In the nexus of the root directory bin \ jsw \ conf \ wrapper.conf file

  修改:wrapper.java.command=C:\Program Files\Java\jdk1.8.0_131\bin\java

  

  3, Nexus installation service

  dos input command nexus install window

  

  

  4, Nexus starts service

  dos nexus start command input window

   

  If you failed to start, there are two main reasons:

    1, Nexus installation directory bin \ jsw \ conf \ wrapper.conf the java configuration error cause failed to start (the possibility of error 1: Wrong version; possibility of error 2: the wrong path).

       2,8081 port is occupied cause fails to start (if non-system process takes, the end of the process can be), or modify the port Jetty to find application-port = 8081 in the Nexus installation currently /conf/nexus.properties file instead 8181 on the line.

 

Four, Nexus preliminary presentation

  1. Open your browser, visit: http: // localhost: 8081 /   nexus /:

  2. Click on the top right corner Log In, with the username: admin, password: admin123 login, you can use more features:

  3. Click on the left Repositories link to see the Nexus built warehouse:

   

  

  4.Nexus warehouse into such categories:

  • hosted hosted repository: mainly used for deployment artifacts can not be obtained from the public warehouses (such as the oracle JDBC driver) as well as their own or third-party members of the project;
  • warehouse proxy agent: Agent public remote repository;
  • virtual virtual warehouse: for adapting Maven 1;
  • group Warehouse Group: Nexus unified by the concept of warehouse management group multiple warehouses, so we request directly to the warehouse group in the project to requests to multiple warehouse warehouse management group.

  5. In order to better use search Nexus, we can set all proxy warehouse Download Remote Indexes is true, which allows to download remote repository indexes.

  After a successful download the index, under Browse Index tab, you can browse all the member information has been indexed, including coordinates, format, Maven dependency xml Code:

  

  

  6. Local Warehouse Management

We talked about type hosted in front of a local warehouse, Nexus predefined three local warehouse, respectively Releases, Snapshots, 3rd Party were to talk about the three preset warehouse is what to do with:

  Releases:

     Here 's where to build our own publishing projects, usually Release version, such as our own to do a project of the FTP Server, the generated artifacts as ftpserver.war, we can use that to build the release of Nexus Releases local repository. About Eligible publishers will be introduced later.

  Snapshots:

     这个仓库非常的有用, 它的目的是让我们可以发布那些非release版本, 非稳定版本, 比如我们在trunk下开发一个项目,在正式release之前你可能需要临时发布一个版本给你的同伴使用, 因为你的同伴正在依赖你的模块开发, 那么这个时候我们就可以发布Snapshot版本到这个仓库, 你的同伴就可以通过简单的命令来获取和使用这个临时版本.

  3rd Party:

    顾名思义, 第三方库, 你可能会问不是有中央仓库来管理第三方库嘛,没错, 这里的是指可以让你添加自己的第三方库, 比如有些构件在中央仓库是不存在的. 比如你在中央仓库找不到Oracle 的JDBC驱动, 这个时候我们就需要自己添加到3rdparty仓库。

  

五、通过Maven发布到Nexus中央仓库

1 . 修改私服中仓库的部署策略

  Release版本的项目应该发布到Releases仓库中,对应的,Snapshot版本应该发布到Snapshots仓库中。Maven根据pom.xml文件中版本号<version>节点的属性是否包含-SNAPSHOT,来判断该项目是否是snapshot版本。如果是snapshot版本,在执行mvn deploy部署命令时,maven会自动将项目发布到Snapshots仓库。要发布项目,首先需要将Releases仓库和Snapshots仓库的“Deployment Policy”设置为“Allow Redeploy”:

  

2 . 配置项目的部署仓库

在项目的pom.xml文件中增加配置:

       <distributionManagement>
        <repository>
            <id>releases</id>
             <url>http://127.0.0.1:8081/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
          <id>snapshots</id>
          <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
       </distributionManagement>

 

3.设置Maven的服务账号和密码

  D:\maven\apache-maven-3.2.5\conf\settings.xml

 

    <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

4.发布项目到Nexus中央仓库

右键项目->run as->maven build……->run

发布成功后,在私服的仓库中就能看到了:

 

六、在Nexus中手动上传项目构件

 

七、Nexus私服库快速导入jar包

1、找到Repositories->Central->Configuration;如下图

备注:图中第三步 是Nexus 默认的工作路径,需要把你本地的 maven 仓库地中的 所有jar包通过 XFTP上传到里面,再Save;

Nexus私服库快速导入jar包结束;

Guess you like

Origin www.cnblogs.com/liandy001/p/11309588.html