Appendix B. Maven Integration for Eclipse

The Eclipse IDE provides support for Maven through the m2eclipse plugin, which has been recently renamed to m2e. The newer versions of the Eclipse IDE (starting from Kepler) come with the m2e plugin available without needing to be installed as an additional component. The m2e plugin uses components called m2e connectors (or Maven plugin connectors) that work as a bridge between Maven and Eclipse and are able to trigger the execution of the Maven plugins declared in our POMs during the automatic build process of the IDE. These connectors are searched in the Eclipse repositories when they are needed, depending on the used Maven plugins.

This way, we can work on a Maven project within the Eclipse IDE as if it were a native Eclipse project. In the next paragraphs, we are going to summarize the most important use cases.

Tip

The m2e plugin is not a Maven plugin, it is a plugin for Eclipse! The m2e plugin must not be confused with the Maven Eclipse Plugin org.apache.maven.plugins:maven-eclipse-plugin (with the prefix eclipse). The latter is a Maven plugin that statically generates/regenerates the Eclipse project files every time we invoke the eclipse:eclipse goal.

In the first chapter, we created our sample project parent POM using the Eclipse IDE. We can very easily create new Maven projects and modules from the Eclipse menu by navigating to New | Project… | Maven. While creating the sample parent POM and its child modules, we could see that other than the pom.xml descriptor, the Eclipse project files had also been created.

In addition, we can import existing Maven projects into the Eclipse IDE, or we can check them out from an SCM repository like SVN or CVS.

Importing existing Maven projects

By navigating to Import… | Existing Maven Projects…, we can select the project to import in the Eclipse IDE as shown in the following screenshot:

Importing existing Maven projects

Import existing Maven projects

Tip

In this sample, we suppose that we created the parent project POM from the Eclipse IDE, and all the other by hand outside Eclipse, so that we need to import them into the IDE.

If we look in the Package Explorer view, we can see that all the project structures are recognized: the directories /src/main/java, /src/main/resources, and so on are displayed as source folders and the dependencies are visible under the Maven Dependencies classpath folder. This is shown in the following screenshot:

Importing existing Maven projects

Structure of an imported Maven project

If we look in the Navigator view or in the filesystem, we can see the Eclipse project configuration that is formed by the .project and .classpath files and by the .settings directory. These files and directories have been created by Eclipse itself while importing the project, on the basis of the Maven POM.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset