Building a Maven Project

See Also 

The Maven build lifecycle has defined phases with goals that are executed when building and distributing the project. When you execute a goal, Maven will also execute all the preceding goals in the build lifecycle. You can invoke phase goals and plugin goals by mapping the goals to IDE actions, or you can create custom goals and invoke the goals individually. When you execute a goal, the Maven output with the plugin and goal identifiers are displayed in the Output window.

You do not need to build the project or compile individual classes to run the project in the IDE. By default, the IDE automatically compiles classes when you save them. These incrementally compiled files are stored in a cache in your user directory and are copied to your project's build folder when you run or debug your project.

If you want to generate distributable files for the project, such as JAR files or WAR files, you need to build the project. When you build a Maven project using the IDE's Build command, by default the IDE executes the plugin goals in the install phase of the Maven lifecycle (builds the project and adds the artifact to the local repository).

To build the main project:

  1. Choose Run > Build Main Project (F11).

    The IDE displays the Maven output and any compilation errors in the Output window. You can double-click any error to go to the location in the source code where the error occurred.

You can modify the goals that are executed by the Build command and other IDE commands by modifying Maven settings in the project's Properties window.

To build an individual project and its required projects:

  1. Right-click the project's node in the Projects window and choose Build with Dependencies.

    The Build with Dependencies executes the reactor:make goal.

You can modify the project dependencies by adding libraries in the Projects window or by editing pom.xml in the editor.

Executing Maven Goals in the IDE

IDE actions in the popup menu are mapped to Maven phases and goals. For example, by default the Build action in the IDE is mapped to the install phase in the Maven lifecycle. When you right-click the project node and choose Build, the IDE executes the goals described in the install phase to package the project and executes all the goals in the preceding phases in the build lifecycle.

You can modify the mapped Maven goals that are invoked by IDE actions by configuring actions in the project's Properties window or in the Maven tab in the Options window. For more, see Configuring Maven settings.

Customizing the Build Process

To customize the build for a Maven project you modify the POM to add or reconfigure plugins and dependencies. You can use the code completion in the editor to help you when adding details to pom.xml.

  1. Open pom.xml in the XML editor.
  2. Choose Source > Insert Code (Ctrl-I) from the main menu and select Plugin from the popup menu to open the Add New Plugin dialog box.
  3. Type a query term to search for the plugin.
  4. Select the plugin from the list of available plugins.
  5. Select the goals that you want to be executed. Click OK.

When you click OK, the IDE adds the plugin description to pom.xml and the goals to run as part of the build process. If you add a plugin that is not in the local repository, the required artifact will be automatically downloaded from a remote repository when required.

See Also
About Working with Maven
Working with the Maven POM
Configuring Maven Settings
Managing Maven Project Dependencies

Legal Notices