Build a Maven private server using sonatype nexus

Source: Internet
Author: User
Tags maven central sonatype sonatype nexus

1. Why is nexus used?

If there is no private server, all the components we need must be downloaded to the local machine through the maven central repository and third-party Maven repository, the repeated download of components from a Maven repository by everyone in a team undoubtedly increases the load on the repository and wastes Internet bandwidth. If the network speed is slow, the project process will be affected. In many cases, project development is performed on the Intranet. What can I do if I cannot connect to the maven repository? How can I develop public components for other projects? At this time, we had to build our own Maven private server for our team, which saved both network bandwidth and accelerated the project building process, of course, the prerequisite is that your private server has all the components required by the project.

2. Download nexus

: Http://www.sonatype.org/nexus/go

3. Start nexus

I downloaded the zip package, decompress it, and enter \ nexus-2.1.2-bundle \ nexus-2.1.2 \ bin \ JSW \. Select the folder Based on the operating system type. I chose the windows-x86-32 folder, the following BAT file is displayed.

Figure (1)

Double-click the console-nexus.bat to run. Enter http: // 127.0.0.1: 8081/nexus/in the browser. The result shown in figure (2) indicates that the nexus is successfully started.

Figure (2)

8081 is the default port number. to modify the port number, go to nexus-2.1.2-bundle \ nexus-2.1.2 \ conf \ to open the nexus. properties file and modify the application-port attribute value.

Default username and password: admin/admin123. After logging on, you can see figure (3:

Figure (3)


 

4. Nexus Repository

There are four types of nexus warehouses:

GROUP: Repository Group

Hosted: Host

Proxy: proxy

Virtual: Virtual

After logging on to nexus for the first time, you can see the next warehouse group and multiple warehouse.


Figure (4)

Public repositories: Repository Group

3rd party: component repository of third-party Release versions that cannot be obtained from public warehouses

Apache snapshots: component repository that uses the snapshot version of the proxy apachemaven Repository

Central: The repository used to release version components in the maven central repository.

Central M1 shadow: used to provide the component image repository of the M1 version in the central repository.

Codehaus snapshots: The repository used to represent the snapshot version component of the codehausmaven Repository

Releases: the host type repository used to deploy and manage internal release component

Snapshots: host type repository used to deploy and manage internal snapshot version components. 5. Configure nexus 5.1 and enable remote indexing.

The new neuxs environment is just an empty repository and needs to be manually synchronized with the remote central database. By default, Nexus disables remote index download. The most important thing is to enable remote index download. Log on to the nexus system. The default username and password are admin/admin123.

Click Repositories under the Administration menu on the left, find the three repositories Apache snapshots, codehaus snapshots, and Maven central in the repository list on the right, and then change download remote indexes to true without the repository configuration. For example

 

 

Right-click the Apache snapshots, codehaus snapshots, and Maven central repositories and select repari index. Then, Nexus downloads the remote index file.

 

 

 

 

After this setting, Nexus automatically downloads the index file from the remote central repository. to verify whether the automatic download of the index file takes effect, you can switch to the Browse index.

 

 

In the left-side Navigation Pane, there is artifact search. In the input box, enter the name of the component you want to search for, for example, Maven. The query result is as follows:

 

 

5.2 create a host warehouse

Create a new company's internal repository. The procedure is repositories-> Add-> hosted repository. Enter the repository ID and repository name in the lower part of the page. For example, enter

Zfy and zfy repostiory, set deployment policy to allow redeploy, and click Save to complete the creation.

Here, I click "add a repository of the host type". The configuration of the new repository appears below the repository list, as shown below:

Figure (6)

Click Save to view the newly added repository in the repository list.

 

 

5.3,Create a nexus repository Group

The concept of repository group in nexus is not available in maven. In Maven's opinion, whether you are hosted or proxy or group, it is the same for me. I just follow the groupid, artifactid, version, and other information to ask you for components. To facilitate Maven configuration, nexus can combine multiple repositories, hosted, or proxy into one group. In this way, Maven only needs to depend on one group, you can use all the repository content contained in the group.

In neuxs-1.9.2.3, a group named "Public repositories" is provided by default. You can click this group to adjust the warehouse he protects and add zfy repostiory, the company's internal warehouse just created, in this way, you do not need to specify the internal repository address in Maven. Create a group with the group ID public-snapshots and group name public snapshots repositories, and add Apache snapshots, codehaus snapshots, snapshots, and zfy repostiory to the group.

 

 

 

 

 

 

 

The installation and configuration of neuxs are complete. The following describes how to use your private server in Maven.

 

 

 

5.4 create a nexus proxy Repository

Click Add on the menu bar and select proxy repository. The configuration page is shown as follows:

Figure (7)


I have created hosted and group respectively, but have not created a proxy. It has passed the maven test.

6. settings. xml configuration

<?xml version="1.0" encoding="UTF-8"?>  <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"             xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">      <pluginGroups></pluginGroups>    <proxies></proxies>      <servers>        <server>        <id>nexus-releases</id>        <username>admin</username>        <password>admin123</password>      </server>      <server>        <id>nexus-snapshots</id>        <username>admin</username>        <password>admin123</password>      </server>    </servers>      <mirrors>       <mirror>         <id>nexus-releases</id>         <mirrorOf>*</mirrorOf>         <url>http://localhost:8081/nexus/content/groups/public</url>       </mirror>      <mirror>         <id>nexus-snapshots</id>         <mirrorOf>*</mirrorOf>         <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>       </mirror>     </mirrors>        <profiles>     <profile>        <id>nexus</id>        <repositories>          <repository>            <id>nexus-releases</id>            <url>http://nexus-releases</url>            <releases><enabled>true</enabled></releases>            <snapshots><enabled>true</enabled></snapshots>          </repository>          <repository>            <id>nexus-snapshots</id>            <url>http://nexus-snapshots</url>            <releases><enabled>true</enabled></releases>            <snapshots><enabled>true</enabled></snapshots>          </repository>        </repositories>        <pluginRepositories>           <pluginRepository>                  <id>nexus-releases</id>                   <url>http://nexus-releases</url>                   <releases><enabled>true</enabled></releases>                   <snapshots><enabled>true</enabled></snapshots>                 </pluginRepository>                 <pluginRepository>                   <id>nexus-snapshots</id>                    <url>http://nexus-snapshots</url>                  <releases><enabled>true</enabled></releases>                   <snapshots><enabled>true</enabled></snapshots>               </pluginRepository>           </pluginRepositories>      </profile>    </profiles>      <activeProfiles>        <activeProfile>nexus</activeProfile>    </activeProfiles>     </settings>

7. Configure Pom. XML in Maven

<PRE class = "html" name = "code"> <distributionmanagement> <! -- Two IDs must be associated with setting. <Server> <ID> nexus-releases </ID> </Server> in XML must be consistent --> <repository> <ID> nexus-releases </ID> <Name> nexus release repository </Name> <URL> HTTP: // localhost: 8081/nexus/content/repositories/releases </URL> </Repository> <snapshotrepository> <ID> nexus-snapshots </ID> <Name> nexus snapshot repository </Name> <URL> HTTP: // localhost: 8081/nexus/content/repositories/snapshots </URL> </snapshotreposi >></Distributionmanagement> </PRE> <PRE class = "html" name = "code"> </PRE> <PRE class = "html" name = "code"> 8. MVN: the deploy command uploads the package and finds that the download path is not the path of the central database, but the path of the Repository group in nexus. This indicates that the environment is successfully configured. </PRE> <PRE class = "html" name = "code">   </PRE> <PRE class = "html" name = "code"> </PRE>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.