Installation and configuration of Maven series (II), and configuration of maven Series

Source: Internet
Author: User

Installation and configuration of Maven series (II), and configuration of maven Series
Check the JDK Environment

Before installing Maven, make sure that you have installed JDK correctly. Maven can run on JDK 1.4 or later.

Open cmd and enter java-version.

Download Maven

Maven Official Website: http://maven.apache.org/download.html

Download the latest version of Maven 3.3.9.

Decompress the downloaded apache-maven-3.3.9-bin.zip file to the C: \ Program Files directory, and then add the environment variables as follows:

Open the System Properties Panel (right-click my computer> properties on the desktop), click Advanced System settings, and then click environment variables to create a new variable in the system variables, variable name M2_HOME, variable value is Maven installation directory C: \ Program Files \ apache-maven-3.3.9-bin \ apache-maven-3.3.9.

Click "OK", find a variable named Path in the system variable, and add % M2_HOME % \ bin at the end of the variable value.

Then, enter mvn-v in cmd to check whether Maven is successfully installed:

There is a small problem here. Because the JAVA_HOME variable is not configured in the Path environment variable, Maven cannot find the dependent JDK. We only need to add the JAVA_HOME variable to the Path, for example:

Then restart cmd (after changing the environment variable, restart cmd to identify the changed environment variable ~ Remember), enter the command: mvn-v for example:

In this case, Maven is successfully installed ~~~

The knowledge of Path is popularized here: When we enter commands in cmd, Windows first searches for executable files or scripts in the current directory, windows then traverses the Path defined in the environment variable Path.

Because % M2_HOME % \ bin is added to Path, Here % M2_HOME % actually references another variable defined previously, and its value is the Maven installation directory. Therefore, Windows searches for the directory C: \ Program Files \ apache-maven-3.3.9-bin \ apache-maven-3.3.9 \ bin while executing the command, where mvn executes the script.

 

Upgrade Maven

Maven updates are frequent, so users often need to update Maven installation to get more and cooler new features and avoid some old bugs.

It is easy to update Maven on Windows. You only need to download the new Maven Installation File, decompress it to the local directory, and then update the M2_HOME environment variable.

Installation Directory Analysis

As mentioned above, set the M2_HOME environment variable to point to the Maven installation directory. All the other places that use M2_HOME later refer to the installation directory.

First look at the structure and content of the Directory, such:

Bin:

The directory contains the scripts run by mvn, where mvn is a shell script based on the UNIX platform, and mvn. bat is a bat script based on the Windows platform. When you enter any mvn command in the command line, these scripts are actually called.

This directory also contains the mvnDebug and mvnDebug. bat files. What are the differences and relationships between mvn and mvnDebug? Open the file and we can see that the two are basically the same, but mvnDebug has an additional MAVEN_DEBUG_OPTS configuration. Its role is to enable debug when running Maven to debug Maven itself.

In addition, this directory also contains the m2.conf file, which is the configuration file of classworlds and will be introduced later.

Boot:

This directory contains only one file, taking maven 3.3.9 as an example, which is a plexus-classworlds-2.5.2.jar. Plexus-classworlds is a Class Loader framework. Compared with the default java class loader, it provides richer syntax for convenient configuration. Maven uses this framework to load its own class libraries.

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.