Manage Eclipse Maven Project
In the previous tutorial we installed M2E Plugin and created Maven Project with it. In this tutorial, we describe the features of M2E that are useful to manage Eclipse Maven Project.
POM Editor
When we open pom.xml in Eclipse, M2E opens it in GUI POM Editor shown in the screenshot.
The Overview tab is useful to manage project coordinates, parent or modules of the project and properties. With the Dependencies tab, we can manage project dependencies. While the Dependency Hierarchy tab shows how project dependencies are organized, the Effective POM tab displays the effective POM of the project. The last tab, pom.xml. is the source editor.
Add Dependency
To add dependencies, go to Dependency Tab of the POM Editor and click Add button to open the Add Dependency window.
Alternatively, select the pom.xml in Project Explorer and right click to open the context menu where we can select Maven → Add Dependency to open the Select Dependency window.
In the Select Dependency window, enter a search string to display matching artifacts from the local or global repository. On selecting an item from the search results, the artifact coordinates are populated. Click OK button to add it as dependency to the project.
Repository Index
Search works only when repositories are properly indexed. Please refer Maven Repository View to rebuild the index.
Add Plugin
To add a Maven Plugin to the project, select the pom.xml in the Project Explorer view and right click to open its context menu. Then, select Maven → Add Plugin to open the Add Plugin window.
In the Add Plugin window, enter a search string to display matching Maven Plugins in local or global repository. On selecting an item from the search results, the plugin coordinates are populated. Click OK button to add plugin to the project.
Edit POM
The last tab of the POM Editor, pom.xml, is useful to view and edit the source of pom.xml.
In the source editor, we can use Alt+Space at any location to know the allowed Maven elements at that level. We can scroll through the list to display the help for each element and select the element which will be inserted to the pom.xml. The screenshot shows the allowed elements within a plugin element and its help message.
Build Maven Project
To build a Maven Project, select the project or its pom.xml in Project Explorer and right click to open the context menu and select Run As to show the available build options.
Among others, the drop down menu shows six Maven build options. The last four build options - Maven clean, Maven generate-sources, Maven install and Maven test executes respective lifecycle phases.
The Maven build… opens the Eclipse’s Edit Configuration dialog, where we can enter Goal or lifecycle phase in Goals field and run the build. When you have multiple run configurations, use Maven build to select and run build from the existing run configurations.