Use Nexus to build a maven

Source: Internet
Author: User

----------------------------------------------------------------------------------------------
[Copyright: The author of this article is original, reproduced please indicate the source]
Article Source: http://blog.csdn.net/sdksdk0/article/details/52190619
Juppé id:sdksdk0 Email: [Email protected]
--------------------------------------------------------------------------------------------


First, Introduction

Maven is an open source project management tool written in Java, and Maven uses a concept called Project Object Model (POM) to manage projects, and all project configuration information is defined in a file called Pom.xml. through this file Maven can manage the entire lifecycle of a project, including purging, compiling, testing, reporting, packaging, deployment , and more. Currently, most of Apache's projects have been managed using MAVEN. Instead of wasting time learning how to rely on jars in different environments , MAVEN itself supports a variety of plugins that allow for more flexible control of the project, and the main task for developers is to focus on business logic and implement it . Packages , Project deployment, and more .


Both Maven and Ant are software building tools (software management tools), and MAVEN is more powerful than Ant and has replaced the declarative dependency description of the Ant,jar package. Maven has a repository of jar packages. SVN is a software version control tool that is a collaborative development tool. The SVN warehouse stores the project source code, the historical version of the backup, the declaration of each version of the changes.


Second, setting up the scene

Some companies do not provide the network to the project team, so you can not use MAVEN to access the remote warehouse address, it is necessary to find a network in the LAN access to a machine, to build a nexus, and then developers to connect to this server, This will allow you to access MAVEN's remote repository through this PC with a nexus.

If an IP address maliciously downloads central repository content, such as 100 machines across the company using the same IP over and over again, the IP (or even the IP segment) will be blacklisted, so using Maven on a slightly larger scale should be used with a nexus.


Third, Nexus deployment
: http://www.sonatype.org/nexus/

First step: Download the Nexus-webapp-2.6.2.war package and copy it to the WebApps directory under Tomcat

Second step: Start the Tomcat default login account password: admin admin123, click on the upper right corner to sign in.

Step Three: Access the HTTP://LOCALHOST:8080/project name/




Iv. Repository

Nexus Default address of the warehouse , Nexus-2.1.2\web-inf\plexus.properties defined in the

Configured in Views/repositories-->repositories, the Nexus can be configured with 3 types of warehouses, namely proxy, hosted, group

Proxy: Is the remote Repository agent. For example, in the Nexus configuration of a central repository proxy, when the user to this proxy request a artifact, the proxy will be local lookup, if not found, will be downloaded from the remote repository, and then returned to the user, is equivalent to a relay role

Hosted : is the host warehouse, users can put some of their own components, deploy to hosted, can also manually upload components into the hosted. For example, Oracle driver, Ojdbc6.jar, in central repository is not available, you need to manually upload to hosted

Group : It's a warehouse group, and there's no such concept in Maven, which is unique to the nexus. The purpose is to aggregate the above multiple warehouses, exposing the user to a unified address, so that users do not need to configure multiple addresses in the Pom, as long as the unified configuration of the address of the group can be the right side of the repository path can be clicked to see the Artifact list in the warehouse. However, be aware of the browser cache.

Virtual : also central warehouse image, support M1 old version



- hosted: The host warehouse, which belongs to the company's private
1. 3rd part: Third-party jar package, but the jar package is not saved in the central repository, drive. jar
2. Snapshot: Beta version, mirrored version Easynet.war
3. Release: Release
- proxy: Agent warehouse: Jar package for agent Center Warehouse

- Public: Warehouse Group: Virtual Concepts can contain other warehouses


Upload jar package to nexus5.1 directly in Nexus Management background upload

Select the library you want to upload directly, and set the group. Here is an example of a jar that passes pig. Select the 3rd party, and then fill in maven coordinates (groupid+artifactid+version).



We can see in the browser whether the upload was successful. Here you can see that there is already pig in this folder.





5.2 Uploading using MyEclipse

Configuring Maven in MyEclipse I'm not going to explain here, there's a lot of information on the web. We can create a new Web project in MyEclipse named: Nexusmaven and add maven support for it. Find the Pom.xml in the generated MAVEN project and configure it as follows.


    <distributionManagement>  <!--released to the snapshot version of the warehouse, i.e. test version Warehouse--  <snapshotRepository>  <id >snapshots</id>  <url>http://127.0.0.1:8080/nexus-2.6.2/content/repositories/snapshots/</ url>  </snapshotRepository>  <!--released to the release version of the warehouse, can also be published to the 3rd party warehouse--  <repository>    <id>releases</id>  <url>http://127.0.0.1:8080/nexus-2.6.2/content/repositories/ releases/</url>  </repository>  </distributionManagement>  


Also need to add account password support to our MAVEN conf directory under Settings.xml. In servers, which is approximately 114 lines later, configure:

<server>      <id>releases</id>      <username>admin</username>      <password >admin123</password>    </server><server>      <id>snapshots</id>      < username>admin</username>      <password>admin123</password>    </server>

Then go back to our MyEclipse project, right-click on this project, run as--maven build, and enter deploy for deployment.





So our project was uploaded to the list.



You can see the project we just uploaded in the total browser.




Vi. downloading (referencing) jar packages from a.

Similarly, it is configured in Pom.xml in the previously created MAVEN project.


<!--relies on Pig.jar packages, existing in-and <!--maven coordinates--<dependency> <groupId>pig</groupId> <artifactId>pig</artifactId> <version>0.12.1</version> </dependency> </depende   Ncies> <!--If there is no one, the local warehouse can not be found, then access the central warehouse if there is a: Access order first access to the local warehouse local warehouse does not have access to the repository, then access the central warehouse -<!--loaded with third-party projects using the jar--<repositories> <repository> <snapshots> &lt ;enabled>true</enabled> </snapshots> <id>public</id> <name>public</name > <url>http://127.0.0.1:8080/nexus-2.6.2/content/groups/public/</url> </repository> </rep Ositories> <!--loaded with the Maven life cycle plugin jar--<pluginRepositories> <pluginRepository> <rele ases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <en Abled>true</enabled> </snapshots> <id>public</id> <name>public</name> <url>http:/ /127.0.0.1:8080/nexus-2.6.2/content/groups/public/</url> </pluginRepository> </pluginrepositories >


Summary: Using a nexus to build a MAVEN private server is a very useful feature, and the MAVEN environment is no longer repetitive. When the project team developer develops, the jar can be obtained by adding the following pom.xml information in the project's Pom.xml file. If additional artifacts are added, they will be downloaded on the Nexus before being downloaded locally. Later, if a jar package is found, it will be downloaded directly from the Web, if it is not downloaded on the network. This is the benefit of setting up a.


SOURCE Download: Https://github.com/sdksdk0/nexusMaven






Use Nexus to build a maven

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.