MAVEN installation and integration with Eclipse

Source: Internet
Author: User

1. Installation

MAVEN does not need to be installed as a service component on Windows, just download, unzip, and configure the environment variables.


1.1 jdk and Java_home

Before installing MAVEN, make sure you have the JDK installed correctly. MAVEN can run on versions JDK1.4 and above. Run the command "echo% java_home%" to check whether the environment variable java_home points to the correct JDK directory, and then run the command "Java-version" to check if the JDK version is in version 1.4 and above.


1.2 Download maven

Download maven3.x (e.g. Maven3.2.3, currently developed to Maven3.25 version) http://maven.apache.org/download.html All we need to do is download the Apache-maven-3.2.3-bin.zip file. If you're interested in Maven's source code and want to build maven yourself, you can also download apache-maven-3.2.3-src.zip.


1.3 Decompression

Download complete, only need to extract apache-maven-3.2.3-bin.zip files, such as my put to: F:\maven directory, such as:


    


Then configure the two environment variables:

maven_home: F:\maven\apache-maven-3.2.3

Path(in which to add):%maven_home%\bin;


1.4 Verification

Open the command line and enter: Echo%maven_home% to see if the configured Maven_home directory is correct, such as:

    


Open the command line and enter: Mvn–version. If the output is as follows, the MAVEN installation is successful:

    


2. Catalogue Introduction

As in the contents of the directory:


  


-Bin :

The directory 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. Where MVN is the UNIX platform-based shell script, Mvn.bat is a Windows platform-based bat script. When you enter any of the MVN commands on the command line, these scripts are actually called. The directory also contains the Mvndebug and Mvndebug.bat two files, which, again, are shell scripts for the UNIX platform, which is the Windows bat script. So what's the difference between MVN and mvndebug? Open the file we can see, the two are basically the same, but mvndebug more than a maven_debug_opts configuration, the role is to run Maven when the debug, in order to debug maven itself.


-Boot :

This directory contains only one file, with Maven 3.0 as an example, and the file is Plexus-classworlds-2.2.3.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. For more information about Classworlds, please refer to http://classworlds.codehaus.org/. For a typical MAVEN user, you don't have to care about the file.


-Conf :

This directory 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 are more inclined to copy the file to the ~/.m2/directory (here ~ to represent the user directory) and then modify the file to customize the behavior of Maven in the user scope .


-Lib :

The directory contains all of the Java class libraries required by the MAVEN runtime, and Maven itself is a sub-module development, so users can see things like Mavn-core-3.0.jar, Files like Maven-model-3.0.jar, and also contains some third-party dependencies such as Common-cli-1.2.jar, Google-collection-1.0.jar, and so on that Maven uses. (For Maven 2, the directory contains only one MAVEN module, such as Maven-2.2.1-uber.jar, that was originally a standalone jar file, and the third-party class library was disassembled and merged back into the jar file). It can be said that this Lib directory is the real maven. One more thing to note about this file is that you can find Maven's built-in super Pom in this directory, which is explained in detail in section 8.5. Other: LICENSE.txt records the software licenses used by Maven Apache LICENSE Version 2.0;notice.txt records the third-party software that Maven contains, while README.txt contains a brief introduction to MAVEN, including installation requirements and brief instructions on how to install them.


3. Integration with Eclipse

Install Maven's M2eclipse plugin in Eclipse. The installation steps are as follows:


3.1 Installation Method one:

Start eclipse,help--> Install New software ...

  


Click the Add button on the work with: field side to get a new Addrepository dialog box

  


In the Name field, enter Http://download.eclipse.org/technology/m2e/releases in the M2e,location field, and then click OK.

  

Eclipse Downloads The resource information on the M2eclipse installation site. After the resource loading is complete, you can see the interface shown in the figure:

  


Select M2eclipse's core module Maven integration for Eclipse (Required), select Click Next button, Eclipse will automatically calculate inter-module dependencies, and then give a list of modules that will be installed. After you confirm the error, continue to click the Next button, and you will see the license information. The open source license used by M2eclipse is the Eclipse public licensevl.0, select I accept theterms of the license agreements, then click the Finish button,

Then wait patiently for the eclipse to download and install the modules.


3.2 Installation Method two:

Start Eclipse,help-->eclipse MarketPlace, enter the maven find M2eclipse plugin in the Open Interface search box, as shown in:


  


Select Maven integrationfor Eclipse, click Install directly, select Confirm, select I accept the termsof the license agreements, then click Finish, Then wait patiently for the eclipse installation to complete.


3.3 Check if the installation is successful

(1) Click Help–about Eclipse


     


Click Installationdetails


     


See if MAVEN integration for Eclipse exists in the installed software directory, such as:


     


(2) Re-check if Eclipse can create a MAVEN project

File-new-other, find the MAVEN entry, and if all is well, the m2eclipse is properly installed.


     



4. Recommended Configuration
4.1 Setting maven_opts environment variables

As we learned in the previous MAVEN installation directory, running the MVN command is actually a Java command, and since it is running Java, the parameters available for running Java commands should of course be available when you run the MAVEN command. At this point, the MAVEN_OPTS environment variable will come in handy.

It is often necessary to set the value of Maven_opts to-xms128m–xmx512m, because the default maximum available memory for Java is often not sufficient to meet the needs of MAVEN operations, such as building a project site with Maven when the project is large, requiring a lot of memory, if not, It is easy to get java.lang.Out0fMemeoryError. Therefore, it is recommended to configure the variable at the outset.


4.2 Configuring user Scope Settings.xml

The user can choose to configure $maven_home/conf/settings.xml, or ~/.m2/settings.xml. The former is global in scope, and all users on the entire machine are directly affected by the configuration, which is user-scoped and only the current user is affected by the configuration.

The use of user-scoped settings.xml is recommended primarily to avoid unintentionally affecting other users in the system. If there is a real need, you need to unify the settings. XML configuration for all users in the system, and of course you should use the global scope of settings. Xml.

In addition to affecting the scope of this factor, configuring a user-scoped settings. xml file also facilitates MAVEN upgrade. Directly modify the Conf directory, Settings.xml will cause MAVEN upgrade inconvenience, each upgrade to a new version of MAVEN, you need to copy settings.xml files if you use SETTINGS.XRNL in the ~/.M2 directory. Does not affect the MAVEN installation files, you do not need to touch the settings.xml file when upgrading.


4.3 do not use the IDE's inline maven

Whether it's eclipse or NetBeans, when you integrate Maven, a built-in MAVEN is installed, which is usually newer, but not necessarily stable, and is often not the same version of Maven that you use on the command line. There are two potential problems: first, newer versions of Maven have a lot of instability, which can be difficult to understand, and second, the command line maven is often used in addition to the IDE, and if the versions are inconsistent, it is easy to create inconsistencies in the build behavior. This is what we don't want to see: Therefore, you should use Maven consistent with the command line when configuring the Maven plugin in the IDE.

In the M2ECLIPSE environment, click Window in the menu bar. And then select Preferences, in the popup dialog, expand the left Maven item, select the Installations subkey, in the right panel, be able to see that there is a default embedded MAVEN installation is selected click Add ... button, then select the Maven installation directory Maven_home, and select this external maven after adding it, such as:


    


5. Summary

This article mainly introduces the installation configuration of MAVEN on Windows operating system, download-unzip-Configure environment variables, and the MAVEN directory information Introduction, It is mainly the settings.xml files that we often operate, and the integration with Eclipse, mainly the installation of the M2eclipse plug-in, and some recommended configurations.

MAVEN installation and integration with Eclipse

Related Article

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.