Setting Up Maven Launch Configurations
Those familiar with Eclipse and Maven will find Maven launch configurations in MyEclipse helpful for launching any basic Maven phase or setting up and launching even complex custom goals. In this tutorial, you will learn how to:
- Run goals and phases from the menu
- Create custom run configurations
This feature is available in MyEclipse.
1. Running Goals and Phases from the Menu
If you have used Maven, you are probably familiar with basic goals and phases and how to call them from the command line, e.g. mvn install
or mvn clean
. In MyEclipse, running Maven commands can be done directly from a context menu.
Right-click the pom.xml file in your Maven project, select Run As, and choose a basic goal.
Running a Maven goal
2. Creating a Custom Maven Launch Configuration
Other goals, such as mvn site, are not listed on the Maven Run As menu by default. You can add custom build configurations and specify other goals.
- Right-click the pom.xml file in your Maven project, and select Run As>Run Configurations.
- Right-click Maven Build, and click New.
Creating a new build configuration - Enter a configuration name, and click Select to select the goals you want to run.
Note: If you click the Select button to specify goals and the goals list is empty, you need to enable the full repository index. To do so, open the Maven Repositories view, and expand Global Repositories. Right-click Central, and select Enable Full Index. It will take several minutes for the indexes to update.
Build configuration details - Click Variables on the Run Configuration window to select a variable for the base directory.
Selecting the project location variable for the base directory - Select the checkboxes to modify the command as necessary. These are equivalent to command line flags.
- Click the Refresh tab, and select the Refresh resources upon completion checkbox.
Refresh tab - Click the Common tab, and select the Debug and Run checkboxes to have this command appear in those menus. Click Apply.
Common tab
3. Creating a Custom Launch Configuration with Parameters
Some Maven commands using plugins might require custom values as part of the command. This section demonstrates adding a parameter to the command.
- Right-click the pom.xml file in your Maven project, and select Run As>Run Configurations.
- Either create a new configuration as shown in Section 2, or duplicate an existing configuration to avoid re-entering the same settings.
- Click Select, to select a goal that requires additional parameters. For example the gpg, sign and deploy file goal command has a -D parameter: mvn deploy -Dgpg-passphrase=thephrase.
- Click Add to add a parameter.
- Enter the parameter name and value, and click OK.
Adding a command parameter - Click Apply. The command is available from the Run drop-down menu.
Custom configuration on the Run icon drop-down