facebook

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.

runmavenmenu
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.

  1. Right-click the pom.xml file in your Maven project, and select Run As>Run Configurations.
  2. Right-click Maven Build, and click New.

    mavenconfig
    Creating a new build configuration
  3. 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.

    newmavenconfig
    Build configuration details
  4. Click Variables on the Run Configuration window to select a variable for the base directory.

    mavenselectvariables
    Selecting the project location variable for the base directory
  5. Select the checkboxes to modify the command as necessary. These are equivalent to command line flags.
  6. Click the Refresh tab, and select the Refresh resources upon completion checkbox.

    mavenconfigrefresh
    Refresh tab
  7. Click the Common tab, and select the Debug and Run checkboxes to have this command appear in those menus. Click Apply.

    mavenconfigcommon
    Common tab
To run the command, select Run Configurations from the Run or Debug menus; or, right-click the pom.xml file, and select Run As>Run Configurations. Select the configuration you want to run, and click Run.

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.

  1. Right-click the pom.xml file in your Maven project, and select Run As>Run Configurations.
  2. Either create a new configuration as shown in Section 2, or duplicate an existing configuration to avoid re-entering the same settings.
  3. 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.
  4. Click Add to add a parameter.
  5. Enter the parameter name and value, and click OK.

    mavenparameter
    Adding a command parameter
  6. Click Apply. The command is available from the Run drop-down menu.

    runmenumavengoals
    Custom configuration on the Run icon drop-down