1. Introduction
building and managing projects with Maven is a great thing to enjoy and we can Maven Central Warehouse Download the required artifacts (artifact), but the actual development for various reasons we need to set up a MAVEN local agent warehouse, such as: inconvenient access to the public network, save bandwidth and time, manage their own shared artifact and so on. The local geodatabase is my own name, in order not to be confused with the local repository below.
The process of getting the build is as follows: When a user builds a project using MAVEN, it is first obtained directly from the local repository, and if the local repository does not, it will first attempt to download artifacts from the remote repository to the local repository, and then use the artifacts of the local warehouse, based on the Setting.xml settings. If the remote repository set up by Setting.xml is the local agent repository, the local agent warehouse tries to get from its own library first, and if it is not downloaded from the remote repository (such as a central warehouse) to the local repository.
Nexus is an excellent MAVEN warehouse manager, also provides a powerful warehouse management function, component search function, it is based on rest, friendly UI is a ExtJS rest client, it occupies less memory, based on simple file system rather than database. These advantages make it increasingly the most popular MAVEN warehouse manager. This article uses Nexus to build a local agent repository.
2. Download and install
Nexus official: Http://www.sonatype.org/nexus/go , the latest version is now 2.7.2.
Nexu installation is very easy because it embeds the jetty, as long as the JRE can be saved to run directly. Extracting the NEXU package will get two directories nexus-2.7.2-03 and sonatype-work,sonatype-work are the default warehouse directories. Running, installing is using the Nexus-2.7.2-03/bin/nexus.bat file, how it is used:
Usage:nexus.bat {Console:start:stop:restart:install:uninstall}
where console is run as console, install is with Windows service hosting, uninstall is uninstalling Windows service, Start is running Windows service, stop is stopping Windows service, restart is restarting Windows Service .
Nexus Default port is 8081, can be modified in Nexus-2.7.1-01/conf/nexus.properties, after startup can be through the address: Http://localhost/:8081/nexus to visit the. The interface is as follows:
3, Management warehouse
The management warehouse needs to log in first, the default login username/password is admin/admin123. Once you're signed in, you'll see the admin item in the left column menu.
Here, you can manage warehouses, configure Nexus Systems, manage tasks, manage users, roles, permissions, view RSS feeds for your system, manage and view system logs, and more.
1, set up the Nexus agent on the public network
If your local agent warehouse server does not have public rights, Nexus has left you the way to use the proxy, click on the right menu "server", on the right to find
Add your proxy server.
2. Warehouse Management
By clicking on the repositories in the left navigation bar, the main panel of the interface will display a list of all the warehouses and warehouse groups, and you will see that the value of their type field is group,hosted,proxy,virtual. Here we do not care about virtual, only the following three different types:
- Hosted, a local agent repository, usually we deploy our own artifacts to this type of warehouse.
- Proxy, the remote repository of proxies, which are used to proxy remote public repositories, such as the MAVEN central repository.
- Group, warehouse groups, which are used to consolidate multiple hosted/proxy warehouses, typically we configure MAVEN to rely on warehouse groups.
How to manage, add and so on, the Nexus is written very clearly, I will not repeat.
3, modify the Setting.xml configuration maven Warehouse
maven Installation after the default is to use the central warehouse, this is to enable Maven out of the box. The default local repository address for MAVEN is ${user.home}/.m2/repository. In other words, a user will have a local repository. You can also customize the location of the local warehouse and modify the ${user.home}/.m2/settings.xml.
First, you need to modify the mirrors:
<mirrors ><!--Mirror | Specifies a repository mirror site to use instead of a given repository. The Repository that | This mirror serves have an ID, that matches, the mirrorof element of this mirror. IDs is used | For inheritance and direct lookup purposes, and must is unique across the set of mirrors. | --><mirror><id>nexusc</id><mirrorof>*</mirrorof><name>nexus</name ><url>http://localhost:8081/nexus/content/groups/public/</url></mirror></mirrors>
when executing the MAVEN command, MAVEN also needs to install some plug-in packages that also point to the address of the local agent repository, modified as follows:
< profile><id>jdk-1.4</id><activation><jdk>1.4</jdk></activation>< Repositories><repository><id>nexus</id><name>local Private Nexus</name><url >http://localhost:8081/nexus/content/groups/public/</url><releases><enabled>true</ enabled></releases><snapshots><enabled>false</enabled></snapshots></ Repository></repositories><pluginrepositories><pluginrepository><id>nexus</id ><name>local Private nexus</name><url>http://localhost:8081/nexus/content/groups/public/ </url><releases><enabled>true</enabled></releases><snapshots><enabled >false</enabled></snapshots></pluginrepository></pluginrepositories></profile
for more setting.xml field explanations please see here .
Now you can build a MAVEN project with a local repository and embark on a pleasant build journey!!
4. Deploy Widgets to Nexus
1. Deployment via Nexus UI
Sometimes there is a jar file that you can't find from a public maven repository, but you can get the jar file (or even Pom) from the other, so you can deploy the file to the Nexus as part of the standard process. The steps are as follows: click "Repository" in the left navigation bar, select a warehouse in the warehouse list on the right, such as "3rd party", then tab at the bottom of the page to select "Artifact Upload Artifact (s)", You will see the widget upload interface. Select the widget you want to upload and specify the pom, (or manually write Gav, etc.), and then click Upload, and the widget is deployed directly to the Nexus "3rd party" warehouse.
2. Deploy through MAVEN
A more common use case is when the team is developing various modules of a project, in order for the module to be developed quickly for others to use, you will want to deploy the snapshot version of the artifacts to the Maven repository, others just need to add a dependency on the POM to your development module, You can always get the latest snapshot.
The following pom.xml configuration and settings.xml enable you to deploy artifacts through MAVEN automation:
Pom.xml
<project>...<distributionManagement> <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> </snapshotrepository></ Distributionmanagement>...</project>
Settings.xml
<settings>...<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>...</settings>
Here we configure all of the snapshot version artifacts to be deployed to the Nexus Snapshots Warehouse, where all release components are deployed to the Nexus releases warehouse. Because the deployment requires logging in, we configure the user name and password corresponding to the repository ID in settings.xml.
Then, execute MVN deploy in the project directory, and you'll see that MAVEN deploys the project artifacts to the Nexus and browses to the Nexus repository to see the artifacts that were just deployed. When others build their projects, Maven looks for dependencies and downloads from the Nexus.
Use Nexus to build MAVEN agent repository