Maven (i)--maven installation and settings.xml configuration

Source: Internet
Author: User
Tags define local xmlns server port
1 maven Installation

Before installing MAVEN, make sure that you have the JDK installed and that the environment variable JAVA_HOME is configured as well. The specific installation steps are as follows:

1. Download the package for the MAVEN project from the Apache web. The download address is: http://maven.apache.org/download.html. For example, now the latest MAVEN version is 3.0.4, then I downloaded a good installation file is Apache-maven-3.0.4.zip.

2. Unzip the downloaded package to MAVEN's installation directory, for example, D:\\develop, then unzip is d:\\develop\\apache-maven-3.0.4.

3. Add the environment variable m2_home, whose value is Maven's home directory, such as d:\\develop\\apache-maven-3.0.4.

4. Add the environment variable M2, whose value will be the bin directory of the MAVEN installation directory, which is D:\\develop\\apache-maven-3.0.4\\bin, which can also be used for Windows systems%m2_home%\\bin, $m2_home/bin can also be used for Linux systems.

5. Add the environment variable M2 to the path variable, and for Windows systems you can add ";%m2%" after the value of the path variable, and for Linux systems you can use the "Export path= $path: $M 2"

6. There is also an optional environment variable, maven_opts, which is primarily configured by Maven to specify JVM properties when using the JDK. Specify its value as "-xms256m-xmx512m".

After these steps, MAVEN installs successfully. Next we can use MVN--version in the command window to verify that MAVEN is installed successfully. If the installed version of Maven is correctly exported, it will be installed successfully.

2 Configuring MAVEN's environment Information

A settings.xml file is provided in Maven to define the global environment information for MAVEN. This file will exist under the Conf subdirectory of the MAVEN installation directory, or the. M2 subdirectory of the user's home directory. We can use this file to define local repositories, remote warehouses, and proxy information used for networking.

In fact, compared to a multi-user PC, the settings.xml under the Conf subdirectory of the MAVEN installation directory is the real global configuration. The configuration of the settings.xml under the. M2 subdirectory of the user's home directory is only for the current user. When these two files are present at the same time, the definitions in the Settings.xml under the MAVEN installation directory are overwritten by the same configuration information as defined in the user home directory under Settings.xml. The settings.xml file in the user's home directory is generally nonexistent, but Maven allows us to define our own settings.xml here, and if we need to define our own settings.xml here, we can put the settings.xml of the MAVEN installation directory to the. M2 directory in the user's home directory, and then change to the look you want.

First look at a basic settings.xml look: XML code    <?xml version= "1.0"  encoding= "UTF-8"?>   <settings xmlns= "http://maven.apache.org/SETTINGS/1.0.0"               xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"               xsi:schemalocation= "http://maven.apache.org/SETTINGS/1.0.0  http://maven.apache.org/xsd/settings-1.0.0.xsd ">                        <localrepository>d:\\ develop\\mavenrepository</localrepository>     <interactivemode>true</ interactivemode>     <offline>false</offline>     < plugingroups>         </pluginGroups>         <proxies>       <proxy>         <id> optional</id>         <active>true</active>          <protocol>http</protocol>          <username>proxyuser</username>          <password>proxypass</password>         

The main elements in Settings.xml include the following:

Localrepository: Represents the directory of the local repository that MAVEN uses to store information locally. The default is the. m2/repository directory below the user's home directory.

Interactivemode: Indicates whether to use interactive mode, which is true by default, and if set to false, it uses a default value when Maven needs the user to enter.

Offline: Indicates whether offline, default is False. This property indicates whether MAVEN is allowed to network to download the required information when MAVEN is doing the project compilation and deployment.

plugingroups: You can define a series of plugingroup elements below the plugingroups element. Indicates where to look for when parsing plugin through the plugin prefix. The Plugingroup element specifies the groupid of the plugin. By default, Maven automatically adds org.apache.maven.plugins and Org.codehaus.mojo to plugingroups.

proxies: The following can define a series of proxy elements that represent the agents that Maven needs to use in networking. When more than one agent is set, the first token that the active is true will be used. Here is an example of using a proxy: XML code <proxies> <proxy> <id>xxx</id> <ACTIVE>TRUE</AC tive> <protocol>http</protocol> <username> user name </username> <PASSWORD&G t; password </password>

Servers: The following can define a series of server sub-elements that indicate the authentication method that needs to be used when connecting to a remote server. This is mainly Username/password and privatekey/passphrase both ways. The following is an example of using servers: XML code <servers> <server> <id>id</id> <username> user name </ username> <password> password </password> </server> </servers>

Mirrors: a mirror used to define a series of remote warehouses. We can define a remote repository to use when downloading artifacts in the POM. But sometimes the remote repository is busy, so at this point people want to create a mirror to ease the pressure on the remote repository, which translates the request to the remote repository to its mirrored address. Each remote repository has an ID so that we can create our own mirror to associate to the repository, and maven can download the artifacts from the remote repository later, which can be downloaded from our well-defined mirror site, which is a good way to relieve the pressure on our remote repositories. Each remote repository in our defined mirror can have only one mirror associated with it, meaning you cannot configure multiple mirror mirrorof to point to the same repositoryid at the same time.

See below is an example of using mirrors: XML code <mirrors> <mirror> <id>mirrorId</id> <mirroro F>repositoryid</mirrorof> <name> define an easy to read name </name> <url>http://my.repository.c Om/repo/path</url> </mirror> </mirrors>

L ID: is used to distinguish mirror, all mirror cannot have the same ID

L Mirrorof: Used to indicate which warehouse the mirror is associated with, and its value is the ID of its associated warehouse. When you want to associate multiple warehouses at the same time, the multiple warehouses can be separated by commas, and when you want to associate all warehouses, you can use "*", which can be expressed as "*,!repositoryid" when you want to associate all warehouses except one warehouse. When you want to associate a warehouse that is not localhost or a file request, it can be represented as "external:*."

L URL: The URL that represents the image. When Maven builds the system, it uses this URL to connect to our remote repository.

profiles: Used to specify a series of profiles. The profile element consists of four elements, activation, repositories, pluginrepositories, and properties. When a profile is active in settings.xml and a profile with the same ID is defined in Pom.xml, the profile in Settings.xml overrides the profile in Pom.xml.

(1) Activation: This is the most important element in profile. Like the profile in Pom.xml, the profile in Settings.xml can change some values in a specific environment, which is specified by the activation element.

Take a look at the following example: XML code

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.