vendredi 4 octobre 2013

Opening a Maven project in Eclipse

  1. Select 'Import...MavenExisting Maven Projects'.
  2. Enter the path to the root folder of the project you're interested in containing the 'pom.xml' or browse to it.
  3. If after entering a path directly you don't see any 'pom.xml' under the 'Projects' field then click on [Refresh].
    Note: If it's the very first time you install Maven then the lookup of the pom.xml files may take few minutes instead of few seconds because some artifacts used as plugins by m2e need to be downloaded.
  4. Make sure the 'pom.xml' file(s) is/are selected and click on [Next >] or directly on [Finish].
  5. You may then select the projects you've opened and use the 'Team' menu to specify the SCM to use (e.g. Git, Mercurial, Subversion, Perforce, CVS...)
  • Each 'pom.xml' defines a Maven project. If a project is a parent one then you may find other 'pom.xml' files in that project sub-folders. Simply make sure that you select them all when doing the importation into Eclipse.
  • You don't have to open all the projects if you need to work only on a sub-project nor have to compile all the projects your project depends on.
    Actually if your project depends on another project and if that other project built artifact is not in your '~/.m2/repository' then Maven will query the default central Maven repositories or the shared one you may have defined in your '~/.m2/settings.xml' (e.g. Artifactory, Nexus...) to get the corresponding artifact that has been built by the continuous integration (CI - e.g. Jenkins).
    In case of SNAPSHOT versions, Maven may get the artifact from the latest successful build by the continuous integration that is available on one of the default central or shared repositories.
  • The result of the build is located under 'target' folder and in case you use the command 'mvn install' inside your local repository '~/.m2/repository/'.
  • You mustn't check into the SCM your Eclipse projects folders and files (i.e. '.classpath', '.project', etc.). The 'm2e' plug-in will figure out the project properties from the 'pom.xml' that replaces all those folders and files. In principle an ignore file for the SCM should help preventing that (e.g. .gitignore, .hgignore, .p4ignore...).

Maven installation on Windows

Note: The following steps are optional if you use the m2e plug-in and don't plan to call Maven from the command line.
See the m2e plug-in installation for details.
  1. Download the ZIP file and extract the folder it contains (e.g. 'apache-maven-3.0.5') to whatever location you like.
    (More recent versions can be downloaded from
  2. In the 'Start' menu right click on 'Computer' and select 'Properties', then click on 'Advanced system settings'.
    In the 'Avanced' tab click on [Environment Variables...].
  3. Create an environment variable 'M2_HOME' which value is the absolute path to the folder you've extracted.
    If that path value contains blank spaces then use the 'MSDOS 8.3' format (e.g. replace 'Program Files' with 'PROGRA~1' or 'Program Files (x86)' with 'PROGRA~2').
    For example your 'M2_HOME' value may be 'C:\PROGRA~1\apache-maven-3.0.5' or 'C:\PROGRA~1\maven' if you rename that extracted folder to 'maven':
  4. Append to your 'Path' environment variable the following: %M2_HOME%\bin;
  5. Make Maven locate and use the right JDK (i.e. version 1.7) by setting the 'JAVA_HOME' environment variable:
    • Either by setting that variable in the 'System Properties' like earlier for the 'M2_HOME' variable:
      Make sure you have already defined the environment variable 'JAVA_HOME' that points to your JDK installation (and not the JRE installation).
      If the path value in 'JAVA_HOME' contains blank spaces then use the 'MSDOS 8.3' format (e.g. replace 'Program Files' with 'PROGRA~1' or 'Program Files (x86)' with 'PROGRA~2') then save that 'JAVA_HOME' environment variable with that modified path value.
      Note: You may also add its 'bin' folder to your 'Path' by appending the following: %JAVA_HOME%\bin;
    • Or by creating/editing the file '%HOMEPATH%\.mavenrc' by adding a content similar the following:
      SET JAVA_HOME=C:\PROGRA~1\Java\jdk1.7.0_15
  6. Verify that your installation is working by opening a new command prompt (i.e. 'cmd.exe') and running the command:
    C:\> mvn -v
    Apache Maven 3.0.4 (r1232337; 2012-01-17 10:44:56+0200)
    Maven home: C:\PROGRA~1\apache-maven-3.0.4
    Java version: 1.7.0_15, vendor: Oracle Corporation
    Java home: C:\PROGRA~1\Java\jdk1.7.0_15\jre
    Default locale: en_US, platform encoding: Cp1252
    OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

Maven 2 Eclipse plugin (m2e) installation

Note: The m2e plug-in comes with its own embedded Maven (Version 3.0.4 or later) and should solve the path to the JDK based on your Eclipse workspace configuration.
  1. Start Eclipse (Indigo, Juno, Kepler or later).
  2. Drag and drop this into an open Eclipse window on the menu bar to install m2e.
    (In case it doesn't work go to
  3. In the opened modal window make sure all the plug-ins to install are selected and click on [Next >], accept the license, and so on...