Working with the Maven 2 Plug-in for Eclipse 3.2
This section covers some of the frequently used features of the Maven 2.x Plug-in for Eclipse.
You need to enable Maven nature on an Eclipse project before the Maven 2 plug-in features are available with your project. Right-click on the project that you want to add Maven support to and select Maven2>Enable.
To ensure your project's directory structure reflects Maven's expectations, you should create your Maven directory structure (either manually or using an Archetype) first and then add the project to Eclipse.
Adding dependencies to a pom.xml is easy using the plug-in. Right-click on the project's pom.xml and select Maven2>Add Dependency. This starts the Repository Search wizard. Type the first few characters of the name of the dependency you're looking for, and the wizard searches the central repository for any matching artifacts. All details of the matching artifacts are presented to you to help you select the dependency. Figure 11 shows the results of a search for JUnit artifacts:
Figure 11. Maven Repository Search wizard
Once you have selected the artifact version you want and click OK, a new
<dependency> element is added to the pom.xml by the plug-in automatically.
A build involving any of the life-cycle phases can be started from Eclipse. First, make sure the Maven-enabled project is currently open. Then, from the Eclipse menu, select Run>External Tools>External Tools.... This displays the External Tools wizard, as shown in Figure 12:
Figure 12. Building via Maven using the Eclipse External Tool wizard
Give this configuration a name and then select a life-cycle phase by clicking the Goals... button. Click Run to run Maven.
The Maven output is displayed on Eclipse's Console tab.