Maven2 Eclipse

From HaFrWiki
Jump to: navigation, search

Requirements

  1. Maven:
    Install Apache Maven2 [1]. Try to install maven not using the Windows registry (ToDo: Explanation howto).
  2. Eclipse:
    Install Eclipse [2].
  3. Eclipse m2Eclipse plug-in:
    Install the maven plug-ins for eclipse.[3].
    In eclipse goto Help -> Software Updates... -> Available Software -> Add Site.
    First you may have to install the EMF Model Transaction Workbench (Search for Workbench in the type filter text).
    Add the site http://m2eclipse.sonatype.org/sites/m2e-e34 and install the m2eclipse plug-in.
  4. Eclipse Subclipse plug-in:
    Install the Subclipse [4] plug-in for accessing Subversion repo's.
  5. Eclipse Mylyn plug-in:
    Install the Mylyn plug-in [5] if a JIRA [6] integration is needed.


Before examining the features of m2eclipse, enable the Maven console in Eclipse.

  1. Open the console by: Window -> Show View ->Console.
  2. Click on the arrow of the Open Console Icon of the Console and select Maven Console.
  3. The downloading of the Repository can be followed in this Console Window.

Create Eclipse Maven project

Maven has plug-ins for Eclipse, IntelliJ, IDEAm JBuilder and Emacs. The focus here is on Eclipse-IDE. To build a project in Eclipse using mvn window command-line, perform the Eclipse plug-in of Maven for eclipse. This is the most basic and also deprecated way of creating an Eclipse Maven Project.

  mvn eclipse

Please use one of the following actions:

  1. Check out a Maven project from a SCM [7] repository (such as Subversion or CVS).
  2. Create a Maven project using a Maven archetype. The usage of a Repository Manager (i.e. Nexus) is important when using a lot of developers and having slow Internet access.
  3. Creating a Maven POM (Project Object Model) file. The creation of a POM file within a project which is already in Eclipse.

Repository location

Eclipse needs to know where your Maven Repository is located. Therefor the class-path variable M2_REPO has to be set. Execute the command:

> mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo

To check the installed Maven2 environment, execute the command:

 > set M
M2_HOME=XXX...                  (Should be set)
M2_REPO=XXX...                  (Must be set)
M2_VERSION=XXX...               (Nice to have set)
MAVEN_OPTS=-Xms256m -Xms512m    (Better be set)
MVN_LOG=ZZZ...                  (Should be set)

Problem

I had a M2_REPO environment variable which is not located at the expected place, which is on a windows machine defined by the environment variable USERPROFILE.
Therefore the M2_REPO is correct, but the mvn command does not record the correct location. In this case look in the file org.eclipse.jdt.core.prefs located in the .metadata\.plugins\org.eclipse.core.runtime\.settings directory.
There is a change that the variable-value in Eclipse is non-modifiable. The most logical reason is that you are using the m2eclipse plugin.
Maven uses the settings.xml file located in %M2_HOME%\conf. If nothing is specified here the default location is used.
All suggested work-a-rounds failed. The last thing I tried has been to remove the m2eclipse plug-in from Eclipse. And that worked. Do-no-add the M2_REPO to your eclipse project by using the maven command (mvn -D<workspace-name> eclipse:add-maven-repo), but manually add the variable to the build-classpath.

Alternative

Create a new classpath variable in Eclipse:

  • Windows -> Preferences -> Build Path -> Classpath Variables page.

See also

top

References

top

  1. Apache Maven, Apache Maven Home Page, download locations, installation- and documentation information.
  2. Eclipse Home Page, the place for download locations, installation and documentation info.
  3. CodeHaua.org, Repository and Documentation of maven repositories and plug-ins.
  4. Tigris Subclipse, home of the Subversion. Subclipse is an Eclipse Team Provider plug-in providing support for Subversion within the Eclipse IDE.
  5. Eclipse Mylyn
  6. Atlassian JIRA, Home page of Atlassian JIRA.
  7. SCM: Source Control Management, version control system.