Maven Learning (vii) warehouse

Source: Internet
Author: User
Tags maven central

* Maven Warehouse

In project development, there will often be a Lib directory under the project directory to hold third-party dependent jar files, such as spring log4j jar files,

the Maven repository is where the jar files (war,zip,pom, etc.) are placed , and all MAVEN projects can get the dependency jar they need from the same MAVEN repository, saving disk resources

It also saves time without a cuff.

In addition, because all jars in the Maven repository have their own coordinates, the coordinates tell maven its group ID, artifact ID, version, packaging method, and so on, so MAVEN projects can be easily dependent on version management.

Neither do you. To submit the jar file to the SCM repository, you can create an organization-level MAVEN repository for all members to use.

* Warehouse Classification

When you run Maven, the dependency artifacts required by MAVEN are obtained directly from the local repository, and if the local repository has a dependency build, use it directly;

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 from the local warehouse.

* Local warehouse default address in ${user.home}/.m2/repository directory (for example: C:\Documents and Settings\administrator\.m2\repository)

To customize the local warehouse location:

Configuration Enter maven/conf Directory edit settings.xml file modify Localrepository node

* Central Warehouse is a default remote repository, after installing MAVEN, we can build a simple project, configure some simple dependencies, then run mvn clean install, the project is built. We did not download any jar files by hand, all because of the presence of the MAVEN central repository, which would look for a remote repository when Maven could not find the required jar file in the local repository, and an original MAVEN installation comes with a remote repository--maven central repository. This MAVEN central repository is defined in the Apache-maven3\lib\maven-model-builder-3.0.4.jar,

Super Pom: \org\apache\maven\project\pom-4.0.0.xml

* Private server is a special kind of remote warehouse in order to save broadband resources and time should be set up in the local area network of a privately owned warehouse servers, Remote Storage Agent WAN on the network for MAVEN users within the LAN,

When Maven needs to download the build, it makes a request to the server, and if there is no build on the server, it is downloaded from an external remote repository, cached in a repository, and served as a maven download request.

* Remote Warehouse Configuration

1. Edit the project Pom file

<repositories>    <Repository>      <ID>Maven-net-cn</ID>      <name>Maven China Mirror</name>      <URL>http://maven.net.cn/content/groups/public/</URL>      <releases>        <enabled>True</enabled>      </releases>      <Snapshots>        <enabled>False</enabled>      </Snapshots>    </Repository>  </repositories>  <pluginrepositories>    <pluginrepository>      <ID>Maven-net-cn</ID>      <name>Maven China Mirror</name>      <URL>http://maven.net.cn/content/groups/public/</URL>      <releases>        <enabled>True</enabled>      </releases>      <Snapshots>        <enabled>False</enabled>      </Snapshots>        </pluginrepository>  </pluginrepositories>  

Under the Repositories node, there can be multiple repository, each repository a unique ID, a name, and, most importantly, the URL of the remote repository.

In addition <releases><enabled>true</enabled></releases> tells Maven to download the releases version of the widget from this repository, and < Snapshots><enabled>false</enabled></snapshots> tells maven not to download the snapshot version of the widget from this repository.

2. Configuring a global remote repository in settings.xml

Configuring the remote repository in the POM for each project is only for the current project, if there are 10 projects that will be configured 10 times configuration can be configured only once, that is, the global configuration in Settings.xml

<Settings>    ...    <Profiles>      < Profile>        <ID>Dev</ID>        <!--repositories and pluginrepositories here -      </ Profile>    </Profiles>    <Activeprofiles>      <Activeprofile>Dev</Activeprofile>    </Activeprofiles>    ...  </Settings>  

* Remote Warehouse Certification

Edit Conf/settings.xml File

<Servers>    <Server>      <ID>Same as Repository->id element in Pom file</ID>      <Privatekey>/path/to/private/key</Privatekey>      <Passphrase>Optional Leave empty if not used.</Passphrase>    </Server>  </Servers>  

The ID of the server element must be exactly the same as the repository element in the POM that requires authentication.

* Build deployment to remote repository

mvn Install installs the artifacts generated by the project to the local Maven repository, andmvn deploy is used to distribute the artifacts generated by the project to the remote MAVEN repository.

The components of the local MAVEN repository are available only to the current user and can be used by all users who have access to the repository after distribution to the remote Maven repository.

Configuring the Distributionmanagement of the POM to specify the deployment location for MAVEN

<Project>      ...      <distributionmanagement>        <Repository>          <ID>Nexus-releases</ID>          <name>Nexus Release Repository</name>          <URL>http://127.0.0.1:8088/nexus/content/repositories/releases/</URL>        </Repository>        <snapshotrepository>          <ID>Nexus-snapshots</ID>          <name>Nexus Snapshot Repository</name>          <URL>http://127.0.0.1:8088/nexus/content/repositories/snapshots/</URL>        </snapshotrepository>      </distributionmanagement>      ...    </Project>    

MAVEN treats the release version of the widget and snapshot version of the widget differently, snapshot the version in the development process, real-time, but not stable, release version is relatively stable.

MAVEN will decide which warehouse to distribute the artifacts to based on the version of your project.

In general, distributing artifacts to remote repositories requires authentication, and if you do not configure any authentication information, you will often get 401 errors. This time, configure the authentication information in Settings.xml as follows:

<Settings>      ...      <Servers>        <Server>          <ID>Nexus-releases</ID>          <username>Username</username>          <Password>Password</Password>        </Server>        <Server>          <ID>Nexus-snapshots</ID>          <username>Username</username>          <Password>Password</Password>        </Server>        </Servers>      ...    </Settings>  

* Mirror

<Settings>  ...    <Mirrors>      <Mirror>        <ID>Maven-net-cn</ID>        <name>Maven China Mirror</name>        <URL>http://maven.net.cn/content/groups/public/</URL>        <mirrorof>Central</mirrorof>      </Mirror>    </Mirrors>  ...  </Settings>  

Maven Learning (vii) warehouse

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.