Maven Combat one: Maven installation and configuration

Source: Internet
Author: User
Tags maven central

    • Maven Real-one MAVEN installation and configuration
      • One installation of Maven
        • Check JDK Installation
        • Download maven
        • Local Installation
          • 1 decompression
          • 2 Setting environment variables
          • 3 Upgrading Maven
      • Two installation directory analysis
        • M2_home
        • M2
      • Three set HTTP proxy
        • Verify that you have direct access to the public Maven central warehouse
        • If you really need a proxy to check if the proxy server is unblocked
        • Edit M2settingsxml
      • Four Eclipse support for Maven
      • Five MAVEN installation Best practices
        • Setting maven_opts Environment variables
        • Configure User Scope Settingsxml
        • Do not use the IDE's inline maven

Maven Combat one: Maven installation and configuration one, install MAVEN1. Check JDK Installation

Maven3.3 requires JDK7 or later

Open the command line:
C:\users\huhu>echo%java_home%
D:\dev\Java\jdk1.8.0_92

C:\users\huhu>java-version
Java Version "1.8.0_92"
Java (TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot (TM) 64-bit Server VM (build 25.92-b14, Mixed mode)

2. Download maven

https://maven.apache.org/download.cgi

Download Apache-maven-3.3.9-bin.zip and its source apache-maven-3.3.9-src.zip

3. Local installation (1) decompression

Unzip to D:\dev\maven
That is, its installation directory is: D:\dev\maven\apache-maven-3.3.9

(2) Setting environment variables:

m2_home:d:\dev\maven\apache-maven-3.3.9

Move it to the end of path:
;%m2_home%\bin

To open a new command line:
C:\users\huhu>echo%m2_home%
D:\dev\maven\apache-maven-3.3.9

C:\users\huhu>mvn-v
Apache Maven 3.3.9 (BB52D8502B132EC0A5A3F4C09453C07478323DC5; 2015-11-11t00:41:47+08:00)
Maven home:d:\dev\maven\apache-maven-3.3.9
Java version:1.8.0_92, Vendor:oracle Corporation
Java Home:d:\dev\java\jdk1.8.0_92\jre
Default LOCALE:ZH_CN, Platform ENCODING:GBK
OS Name: "Windows 7", Version: "6.1", Arch: "AMD64", Family: "DOS"

(3) Upgrading Maven

Download the new MAVEN, unzip to D:\dev\maven, and update the M2_HOME environment variable with its full directory.

Similarly, if you need to use an older version of MAVEN, you only need to edit the m2_home environment variable to point to the old version of the installation directory.

Second, installation directory analysis 1. M2_home

The M2_HOME environment variable points to the installation directory of MAVEN. The structure and content of the installation directory:
Bin
Boot
Conf
Lib
LICENSE
NOTICE
README.txt

Bin
Contains scripts that are run by MVN, which are used to configure Java commands, prepare classpath and related Java System Properties, and then execute Java commands.
The differences and relationships between MVN and Mvndebug:
The content is basically the same, but Mvndebug has a maven_debug_opts= "$MAVEN _debug_opts" configuration, which is to turn on DEBUG when MAVEN is running in order to test maven itself.
M2.conf: Is the configuration file for Classworlds

Boot
Contains only a single file Plexus-classworlds-2.5.2.jar,
Plexus-classworlds is a ClassLoader framework that provides richer syntax for configuration than the default Java ClassLoader, and Maven uses the framework to load its own class libraries.

Conf
Contains a very important file: Settings.xml
By modifying the file directly, you can customize MAVEN's behavior globally on the machine.
In general, we prefer to copy the file into the ~/.m2/directory and then modify the file to customize the behavior of MAVEN within the user scope.

Lib:
Contains all the Java class libraries required by the MAVEN runtime.
The Lib directory is the real maven.
In this directory, you can find Maven's built-in super Pom.

2.~/.m2

Execute a simple command: MVN help:system
This command prints out all of the Java System Properties and environment variables.

The purpose of running this command is to have MAVEN perform a real task,
From the command-line output, you can see that Maven downloads a whole bunch of things from the remote repository, including Mavne-help-plugin, including pom files and jar files. These files are downloaded to the MAVEN local repository.

The. M2 folder can be found under the current user directory. By default, the MAVEN local repository is placed under this folder./m2/repository.
All maven artifacts are stored in the repository for easy reuse.
You can find the Maven-help-plugins pom file and the jar file that you just downloaded in the ~/.m2/repository/org/apache/maven/plugins/maven-help-plugins/directory.

MAVEN determines the location of any component in the warehouse based on a set of rules. Because Maven repositories are transparently presented to MAVEN users through a simple file system, there are times when you can bypass Maven to view or modify warehouse files directly.

By default, there are no directories or files in the ~/.m2 directory except for the Repository warehouse, but most MAVEN users need to copy m2_home/conf/settings.xml files to ~/.m2/settings.xml. This is a best practice.

Third, set the HTTP proxy

Sometimes your company is asking you to use a security-certified proxy to access the Internet, based on security considerations. In this case, you need to configure the HTTP proxy for Maven to allow it to access the external repository normally, and to download the required resources.

1. Verify that you have direct access to the public Maven central warehouse

Ping repo1.maven.org

2. If you really need a proxy, check that the proxy server is unblocked

Telnet Proxy server IP port number

3. Edit ~/.m2/settings.xml

(without the file, copy m2_home/conf/settings.xml)
To add a proxy service configuration:

<settings>  <proxies>    <proxy>      <ID>My-proxy</ID>      <active>True</Active>      <protocol>http</Protocol>      <host>Proxy.host.net</host>      <port>80</Port>      <! -- <username>Proxyuser</username>      <password>Proxypass</password>      <nonproxyhosts>Local.net|some.host.com</nonproxyhosts>-</proxy>  </proxies></Settings>

Proxies can have multiple proxy elements, and if multiple proxy elements are declared, the first active proxy will take effect by default.
Active is true to indicate that the agent is activated.
The most important thing is to specify the correct host and port.
The username, password, and nonproxyhost elements are commented out in the XML above.
When the proxy server requires authentication, you need to configure username and password.
The Nonproxyhost element specifies that the host name does not require a proxy, and you can use | to split the hostname.
In addition, the configuration supports wildcard characters, such as *.google.com, which means that all domain name accesses ending with Google.com do not pass through the proxy.

Iv. Eclipse's support for Maven

The latest version of Eclipse has integrated support for MAVEN: M2E plugin

V. MAVEN installation Best practices 1. Setting MAVEN_OPTS Environment variables

Running the MVN command actually executes the Java command, and since it is running Java, the parameters available for running the Java command can of course be used when running the MVN command.

You typically set the MAVEN_OPTS environment variable with a value of-xms128m-xmx512m. Because the default maximum available memory for Java often does not meet the needs of Maven run.

It is a recommended practice to configure this variable at the outset.

You should try not to modify any of the files in the MAVEN installation directory as much as possible, because the changes will cause trouble with the upgrade.

2. Configure User Scope Settings.xml

M2_home/conf/settings.xml global configuration, modifications will affect all users on the entire machine
~/.m2/settings.xml User-scoped configuration, modifications only affect the current user
The use of user-scoped settings.xml is recommended primarily to avoid unintended effects on other users in the system.
If there is a real need to unify the settings.xml configuration of all users in the system, the global scope of settings.xml should certainly be used.

In addition to affecting the scope of this factor, configuring user-scoped Settings.xml also facilitates maven upgrades. Modifying conf/settings.xml directly can cause Maven to upgrade, and every time you upgrade to a new version of Maven you need to copy the settings.xml file.
If you use Settings.xml in the ~/.M2 directory, the MAVEN installation files will not be affected, and you will not need to touch the settings.xml file when upgrading.

3. Do not use the IDE-embedded maven

Eclipse integrates maven, so it embeds a maven.
This inline maven may not be consistent with the version of Maven used in the command line, in order to make it easier to use the version of Maven.

Using external eclipse in eclipse:
When configuring the Maven plugin in the IDE, use maven that is consistent with the command line:
windows–preferences–maven–installations–add...– Select the Maven installation directory, and after adding it, select the external maven.

Maven Combat one: Maven installation and configuration

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.