Developing with Eclipse and Maven
Chapter 8. Using m2eclipse
The m2eclipse plugin also provides a set of features for working with Maven projects once they are inside of Eclipse. There are many features that ease the ability to use Maven in Eclipse so let’s dive right into them. In the previous section, I materialized a Maven project and selected a subproject from the Apache Camel project named camel-core. We’ll use that project to demonstrate these features.
By right-clicking on the camel-core project, and selecting the Maven menu item, you can see the available Maven features. Figure 8.1, “Available Maven Features” shows a screenshot of this:
Notice in Figure 8.1, “Available Maven Features” the available Maven features for the camel-core project, including:
Adding dependencies and plugins
Updating dependencies, snapshots and source folders
Creating a Maven module
Downloading the source
Opening Project URLs such as the Project Web Page, Issue Tracker, Source Control, and Continuous Integration tool.
Enabling/Disabling workspace resolution, nested Maven modules and dependency management
These features are also big time savers so let’s review them briefly.
If the central Maven repository contains a source artifact for a particular project, you can download the source from the repository and expose it to the Eclipse environment. When you are trying to debug a complex issue in Eclipse, nothing can be easier than being able to right click on a third-party dependency and drill into the code in the Eclipse debugger. Select this option, and m2eclipse will attempt to download the source artifact from the Maven repository. If it is unable to retrieve this source artifact, you should ask the maintainers of the project in question to upload the appropriate Maven source bundle to the central Maven repository.
A Maven POM contains some valuable URLs which a developer may need to consult. These are the project's web page, the URL for the source code repository, a URL for a continuous integration system like Hudson, and a URL for an issue tracker. If these URLs are present in a project's POM, m2eclipse will open these project pages in a browser.
You can configure a project to resolve dependencies from a
workspace. This has the effect of altering the way that Maven locates
dependency artifacts. If a project is configured to resolve dependencies
from the workspace, these artifacts do not need to be present in your
local repository. Assume that project-a and project-b are both in the
same Eclipse workspace, and that project-a depends on project-b. If
workspace resolution is disabled, the m2eclipse Maven build for
project-a will only succeed if
project-b's artifact is present in the local
repository. If workspace resolution is enabled, m2eclipse will resolve
the dependency via the Eclipse workspace. In other words, when workspace
resolution is enabled, project's don't have to be installed in the local
repository to relate to one another.
You can also disable dependency management. This has the effect of telling m2eclipse to stop trying to manage your project's classpath, and it will remove the Maven Dependencies classpath container from your project. If you do this, you are essentially on your own when it comes to managing your project's classpath.