Build your own maven private repository with nexus, and use nexusmaven private

Source: Internet
Author: User

Build your own maven private repository with nexus, and use nexusmaven private

Build your own maven private repository with nexus

When the nexus was just installed, the startup of the nexus failed. It started less than 1 minute and stopped automatically. Later I found the cause:

Java 6 Support EOL
Oracle's support for Java 6 ended in February 2013. Consequentially as of version 2.6 Nexus now requires a Java 7 JRE to run.

That is, 6 is not supported since 2.6.0, and jdk must be later than 7.


1. log on to nexus with the admin user

The download and installation of nexus are very simple, and there are many introductions on the Internet. This article will not be repeated. This section describes the configuration after installation.

The configuration of nexus needs to be completed using the admin role. The default password is admin123. after entering the nexus homepage, click the upper right corner to log on.

 

Then you can configure it in the menu on the left.

 

2. Configure proxy servers for nexus

Because this machine needs to access the Internet through a proxy, you must first configure the proxy Server in Administration --> Server.

 

After configuration, nexus can be connected to the central repository. If the private server's machine can be directly connected to the Internet, skip this step.

3. Configure repository

Configure in Views/Repositories --> Repositories

 

Three types of warehouses can be configured in nexus: proxy, hosted, and group.

Proxy is the proxy of the remote repository. For example, if a central repository proxy is configured in nexus, when the user requests an artifact from this proxy, the proxy will first find it locally. If it cannot be found, it will be downloaded from the remote repository and then returned to the user, which is equivalent to a transit function.

Hosted is the host repository. You can upload some of your components, deploy them to hosted, or manually upload the components to hosted. For example, if the oracle driver, ojdbc6.jar, cannot be obtained in the central repository, You need to manually upload it to the hosted.

A group is a repository group. It is unique to nexus and does not have this concept in maven. The purpose is to aggregate the above multiple warehouses and expose the Unified Address to the user, so that the user does not need to configure multiple addresses in the pom, as long as the group address is configured in a unified manner.

After the nexus is installed, some repository has been initialized and defined. After getting familiar with it, you can delete, add, and edit it on your own.

Click the Repository Path on the right to view the artifact list in the Repository. But pay attention to browser cache. Today, I found that the components have been updated, but cannot be seen in the browser. I thought it was a BUG, but it was actually cached by the browser.

4. Configure the proxy of the Central Repository

The most critical configuration may be the proxy configuration of the Central Repository, because most of the components are obtained through this proxy.

 

After nexus is installed, this proxy is preset. You need to change Download Remote Indexes to true so that nexus can Download the index from centralrepository, before artifact search can be used in nexus

There are some other public maven Repositories on the network. You can set the proxy in nexus in the same way, but not all maven repositories provide the nexus index. In this case, you cannot create an index.

5. Configure hosted repository

Generally, three hosted repository (3rd party, Snapshots, and Releases) are configured to save the third-party jar (such as ojdbc6.jar), the Snapshots in the project team, and the released version in the project team.

 

There is no special configuration here, just the Deployment Policy option. Generally, Snapshots is configured to allow, while Releases and 3rd party are set to disable.

6. Configure group repository

As mentioned above, the group is actually a virtual warehouse. By aggregating the physical warehouse (proxy and hosted), a unified address is exposed to the outside.

 

Note that the warehouse on the left will be aggregated. I made a mistake yesterday. I put all the warehouses on the right, and the result group is not aggregated. It is an empty warehouse...

VII. Configure the User Password

In Security --> Users configuration, right-click the deployment user, select Set Password, and Set a Password. This operation is done to prepare for subsequent submission.

 

8. configure settings. xml on the user's machine

After the preceding seven steps, the nexus configuration is complete. Next, you need to configure it on the development machine of each developer.

The configuration file is in % USER_HOME %/. m2/settings. xml
  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. <Servers>
  6. <Server>
  7. <Id> nexus-snapshots </id>
  8. <Username> deployment </username>
  9. <Password> deployment </password>
  10. </Server>
  11. </Servers>
  12. <Mirrors>
  13. <Mirror>
  14. <Id> nexus </id>
  15. <Name> internal nexus repository </name>
  16. <Url> http: // 10.78.68.122: 9090/nexus-2.1.1/content/groups/public/</url>
  17. <MirrorOf> central </mirrorOf>
  18. </Mirror>
  19. </Mirrors>
  20. </Settings>

Only two elements <mirrors> and <servers> are configured here.

First, an image repository with the id of nexus is configured here. The address is the URL of the public group configured earlier, and then the image destination is central.

The super pom in maven is configured as follows:
  1. <Repositories>
  2. <Repository>
  3. <Id> central </id>
  4. <Name> Central Repository </name>
  5. <Url> http://repo.maven.apache.org/maven2 </url>
  6. <Layout> default </layout>
  7. <Snapshots>
  8. <Enabled> false </enabled>
  9. </Snapshots>
  10. </Repository>
  11. </Repositories>
  12. <PluginRepositories>
  13. <PluginRepository>
  14. <Id> central </id>
  15. <Name> Central Repository </name>
  16. <Url> http://repo.maven.apache.org/maven2 </url>
  17. <Layout> default </layout>
  18. <Snapshots>
  19. <Enabled> false </enabled>
  20. </Snapshots>
  21. <Releases>
  22. <UpdatePolicy> never </updatePolicy>
  23. </Releases>
  24. </PluginRepository>
  25. </PluginRepositories>

Therefore, when the required components (including jar packages and INS) cannot be found in the local maven project, they are obtained in central by default.

Therefore, the image repository We Just configured has a central id, so that requests from the local maven project to the central repository will be forwarded to the image repository, that is, the nexus private server we set.

Since other <repositories> and <pluginRepositories> elements are no longer configured in the project pom, you only need to configure a central mirror to prevent all Internet access. If other external network warehouses such as jboss repository are configured in pom, you can change <mirrorOf> *

As for the <servers> element, the reason is that when we upload the components in the project to the nexus repository, nexus will perform permission control, so we need to set the permission-related information here. Note that the <id> nexus-snapshotsid> here is consistent with the pom settings in the maven project.

Because we have blocked requests to the Internet repository, you do not need to configure the proxy server. to configure the proxy server, you can use the <proxies> element.

9. Configure the pom file of the maven Project

The simplified pom file is as follows:
  1. <Project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
  2. Xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <ModelVersion> 4.0.0 </modelVersion>
  4. <GroupId> com. huawei. inoc. wfm. task </groupId>
  5. <ArtifactId> task-sla </artifactId>
  6. <Version> 0.0.1-SNAPSHOT </version>
  7. <Name> task-sla </name>
  8. <! -- Configure the remote repository for deployment -->
  9. <DistributionManagement>
  10. <SnapshotRepository>
  11. <Id> nexus-snapshots </id>
  12. <Name> nexus distribution snapshot repository </name>
  13. <Url> http: // 10.78.68.122: 9090/nexus-2.1.1/content/repositories/snapshots/</url>
  14. </SnapshotRepository>
  15. </DistributionManagement>
  16. </Project>

The <distributionManagement> element is configured here, And the <id> nexus-snapshots </id> element must be consistent with the configuration in the <servers> element in settings. xml described earlier.

The purpose of this configuration is to know which remote repository to deploy the generated component when maven deploy is executed. Note that the URL here is not the address of the public group:
Http: // 10.78.68.122: 9090/nexus-2.1.1/content/groups/public/

But the address of snapshots:
Http: // 10.78.68.122: 9090/nexus-2.1.1/content/repositories/snapshots/

However, in nexus, snapshots is also aggregated to the public group. Therefore, developer A submits the components to snapshots, and developer B can also obtain the components from the public group.

10. settings in eclipse

After the previous configuration, you can use the command line to perform maven operations. However, in actual development, the m2e plug-in of eclipse is generally used, so some additional configuration for eclipse is required.

In Preferences --> Maven --> User Settings, click Update Settings to load the changes we just made to settings. xml.

 

Then, in the Maven Repositories view, you can view the repository information.

 

As you can see, the central inherited from the Super pom is grayed out and unavailable. The mirrored by nexus later indicates that all requests to the repository will be forwarded to the mirror nexus.

11. directory structure of nexus

Nexus will be installed in % USER_HOME %/sonatype-work/nexus, with the following directory

 

The storage directory is the actual storage address of the component.

Related Article

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.