Maven Combat-use Nexus to create a (top)

Source: Internet
Author: User
Tags maven central sonatype

First download Nexus, the official is http://nexus.sonatype.org/download, we can download different bundles according to need, all have. tar.gz,. zip, and. War format
1. Bundle Way to install Nexus
The nexues bundle comes with a jetty container, so the user does not need an additional Web container to launch the Nexus directly. First, the bundle files are extracted to two directories:
NEXUS-WEBAPP-1.7.2/: This directory contains the files needed to run the nexus, such as startup scripts, dependent jar packages
sonatype-work/: This directory contains the nexus generated configuration files, log files, warehouse files, etc.
The default backup Sonatype-work directory when users need to back up the Nexus
The nexus can be started when the window System user enters the NEXUS-WEBAPP/BIN/JSW/WINDOWS-X86-32 subdirectory and runs Nexus.bat directly.
At this point, open the browser http://localhost:8081/nexus/will be able to see the Nexus interface, if you want to stop the Nexus can then command line CTRL + C
Additional Script descriptions:
Installnexus.bat: Installing a Nexus into a window service
Uninstallnexus.bat: Uninstalling the Nexus Window service
Startnexus.bat: Start Nexus Window Service
Stopnexus.bat: Stop Nexus Window Service
Pausenexus.bat: Pause Nexus Window Service
Resumenexus.bat: Resuming a paused Nexus window service
Other installation and installation methods will not be introduced
2. Login Nexus
Nexus default admin username and password is admin/admin123
Nexus warehouses and warehouse groups
1. Nexus Built-in warehouse
The repositories link in the left navigation bar of the standalone Nexus interface is as follows:

You can see four types of warehouses: Group (Warehouse Group), hosted (host), Proxy (proxy), and virtual. In addition, the warehouse has a property of policy, which indicates whether the warehouse is a release or snapshot (Snapshot) version of the warehouse. The value of the last two columns is the state and path of the warehouse.
Explain the role of each warehouse:
1, MAVEN Central: The warehouse agent maven centralized warehouse, its policy is release, so only download and cache the central warehouse release build widget
2. Releases: This is a host-type warehouse with policy release, used to deploy release build artifacts within your organization
3. Snapshots: This is a host-type warehouse with a policy of snapshot, which is used to deploy snapshot version artifacts within the organization
4, 3rd party: This is a host-type warehouse with policy release, which is used to deploy third-parties version artifacts that cannot be obtained from a public warehouse
5, Apache snapshots: This is a policy for the Snapshot Agent warehouse, used to proxy Apache maven Warehouse Snapshot version widget
6. Public repositories: The Warehouse group aggregates all the above-mentioned policies as release warehouses and provides services through a consistent address
7. Public Snapshot repositories: The Warehouse group aggregates all of the above policies into Snapshot warehouses and provides services through a consistent address
Nexus Warehouse Classification Concept

As you can see, maven can download artifacts directly from the host repository, and Maven can also download artifacts from the agent repository, and the agent repository will indirectly download and cache artifacts from the remote repository. Finally, to make it easy for maven to download artifacts from a warehouse group, and the Warehouse group has no actual content, he will be directed to the host repository or to the agent repository for the actual artifact content.
After logging in, click the Add button to create various types of warehouses, as shown in:

Configure maven to download widgets from Nexus
When you need to add a public warehouse on a nexus to your project, configure the following:

<project>...<repositories>        <repository>            <ID>Nexus</ID>            <name>Nexus</name>            <URL>Http://localhost:8081/nexus/content/groups/public</URL>            <releases>                <enabled>True</enabled>            </releases>            <snapshots>                <enabled>True</enabled>            </Snapshots>        </repository>    </repositories>    <pluginrepositories>        <pluginrepository>            <ID>Nexus</ID>            <name>Nexus</name>            <URL>http://localhost:8081/nexus/context/groups/public/</URL>            <snapshots><enabled>True</enabled></Snapshots>        </pluginrepository>    </pluginrepositories>...</Project>

Such a configuration is only valid for the current MAVEN project, and in practice we often want to use a single configuration to make all of our MAVEN projects work with our own maven.
At this point we think of the settings.xml file, where the configuration is valid for all native MAVEN projects, but Settings.xml does not support the direct configuration of repositories and pluginsrepositories. Fortunately, Maven also provides a profile mechanism that allows the user to place the warehouse configuration in the settings.xml profiles, with the following code:

<settings>...<profiles>        <profile >            <ID>Nexus</ID>            <repositories>                <ID>Nexus</ID>                <name>Nexus</name>                <URL>http://localhost:8081/nexus/content/groups/public/</URL>                <releases><enabled>True</enabled></releases>                <snapshots><enabled>True</enabled></releases>            </repositories>            <pluginrepositories>                <pluginrepository>                    <ID>Nexus</ID>                    <name>Nexus</name>                    <URL>http://localhost:8081/nexus/content/groups/public/</URL>                    <releases><enabled>True</enabled></releases>                    <snapshots><enabled>True</enabled></releases>                </pluginrepository>            </pluginrepositories>        </profile >    </Profiles>    <activeprofiles>        <activeprofile>Nexus</activeprofile>    </activeprofiles>...</Settings>

This configuration uses a profile with the Nexus ID, which contains the relevant warehouse configuration, and the Activeprofile element is used in the configuration to activate the Nexus profile. This enables the active profile to apply the warehouse configuration to the project when the MAVEN build is executed. In addition to the Nexus Download Widget, MAVEN also accesses the central repository centrally, and we hope that all Maven download requests will only be made through the nexus to fully function. This needs to be configured with the MAVEN image. You can create a mirror that matches any warehouse, and the mirror address is a single, so that the request for a component download from Maven to any warehouse will be transferred to the database, configured as follows:

<settings>...<mirrors>        <mirror>            <ID>Nexus</ID>            <mirrorof>*</mirrorof>            <URL>Http://localhost:8081/nexus/content/groups/public</URL>        </Mirror>    </mirrors>    <profiles>        <profile >            <ID>Nexus</ID>            <repositories>                <repository>                    <ID>Central</ID>                    <URL>Http://central</URL>                    <releases><enabled>True</enabled></releases>                    <snapshots><enabled>True</enabled></releases>                </repository>            </repositories>            <pluginrepositories>                <pluginrepository>                    <ID>Central</ID>                    <URL>Http://central</URL>                    <releases><enabled>True</enabled></releases>                    <snapshots><enabled>True</enabled></Snapshots>                </pluginrepository>            </pluginrepositories>        </profile >    </Profiles>    <activeprofiles>        <activeprofile>Nexus</activeprofile>    </activeprofiles>...</Settings>

What needs to be explained here is the warehouse plug-in and the plug-in warehouse configuration, their ID is central, covering the Super Pom centralized warehouse configuration, their URLs are irrelevant, because all requests will be mirrored to access the address. The primary purpose of configuring warehouses and plug-in warehouses is to enable support for snapshot version downloads. When Maven needs to download a release version or a snapshot widget, first check the central to see if the type widget supports the download, get a positive answer, and then switch to the repository address based on the mirror matching rules.

Maven Combat-use Nexus to create a (top)

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.