Nexus private server makes Maven more powerful

Source: Internet
Author: User
Tags maven central

Maven is briefly introduced in the front, and the central repository provided by Maven by default is provided in the remote network service appache, which is unreasonable for our development. What should we do if we have no network connection or what happens? That is to say, our team's central warehouse is highly dependent. The Nexus private server can solve this problem. Let's take a look at this picture before you can understand it:




This is equivalent to building a server similar to a central warehouse on our local LAN. We started to download some information from the central warehouse to the private server, then, our Maven project can directly access the private server in the LAN, which not only saves network bandwidth but also accelerates the process of project setup. For our development, it is a good choice for the company. Let's take a look at the simple use of the nexus private server:


1. Download nexus

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

 

2. 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.




Double-click the console-nexus.bat to run. Enter http: // 127.0.0.1: 8081/nexus/in the browser, as shown in.


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.

 

The default username and password are admin/admin123. After logging on, you can see the following figure:


3. 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.


Publicrepositories: 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: the host type repository used to deploy and manage internal snapshot version components.

4. Configure nexus

 

4.1 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:


4.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, fill in zfy and zfy repostiory respectively, 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:




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

 

 

4.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 snapshotsrepositories, 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.

 

 

 

4.4 create a nexus proxy Repository

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


5. settings. xml configuration

1.<?xml version="1.0" encoding="UTF-8"?>  2.<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"   3.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   4.          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  5.  6.  <pluginGroups></pluginGroups>  7.  <proxies></proxies>  8.  9.  <servers>  10.      <server>  11.      <id>nexus-releases</id>  12.      <username>admin</username>  13.      <password>admin123</password>  14.    </server>  15.    <server>  16.      <id>nexus-snapshots</id>  17.      <username>admin</username>  18.      <password>admin123</password>  19.    </server>  20.  </servers>  21.  22.  <mirrors>   23.    <mirror>   24.      <id>nexus-releases</id>   25.      <mirrorOf>*</mirrorOf>   26.      <url>http://localhost:8081/nexus/content/groups/public</url>   27.    </mirror>  28.    <mirror>   29.      <id>nexus-snapshots</id>   30.      <mirrorOf>*</mirrorOf>   31.      <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>   32.    </mirror>   33.  </mirrors>   34.   35.  <profiles>  36.   <profile>  37.      <id>nexus</id>  38.      <repositories>  39.        <repository>  40.          <id>nexus-releases</id>  41.          <url>http://nexus-releases</url>  42.          <releases><enabled>true</enabled></releases>  43.          <snapshots><enabled>true</enabled></snapshots>  44.        </repository>  45.        <repository>  46.          <id>nexus-snapshots</id>  47.          <url>http://nexus-snapshots</url>  48.          <releases><enabled>true</enabled></releases>  49.          <snapshots><enabled>true</enabled></snapshots>  50.        </repository>  51.      </repositories>  52.      <pluginRepositories>  53.         <pluginRepository>  54.                <id>nexus-releases</id>  55.                 <url>http://nexus-releases</url>  56.                 <releases><enabled>true</enabled></releases>  57.                 <snapshots><enabled>true</enabled></snapshots>  58.               </pluginRepository>  59.               <pluginRepository>  60.                 <id>nexus-snapshots</id>  61.                  <url>http://nexus-snapshots</url>  62.                <releases><enabled>true</enabled></releases>  63.                 <snapshots><enabled>true</enabled></snapshots>  64.             </pluginRepository>  65.         </pluginRepositories>  66.    </profile>  67.  </profiles>  68.  69.  <activeProfiles>  70.      <activeProfile>nexus</activeProfile>  71.  </activeProfiles>  72.   73.</settings>  

6. Configure Pom. XML in Maven


1. <PRE class = "html" name = "code"> <distributionmanagement> 2. <! -- Two IDs must be associated with setting. <Server> <ID> nexus-releases </ID> </Server> in XML must be consistent --> 3. <repository> 4. <ID> nexus-releases </ID> 5. <Name> nexus release repository </Name> 6. <URL> http: // localhost: 8081/nexus/content/repositories/releases </URL> 7. </Repository> 8. <snapshotrepository> 9. <ID> nexus-snapshots </ID> 10. <Name> nexus snapshot repository </Name> 11. <URL> http: // localhost: 8081/nexus/content/repositories/SNA Pshots </URL> 12. </snapshotrepository> 13. </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> 14. <PRE> </PRE> 15. <PRE> </PRE>


Well, in the future, some of them will come from network materials. All in all, we know the principle of Nexus. nexus is just a tool. We can build and use it in practice. Learning ......




Nexus private server makes Maven more powerful

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.