Developing with Eclipse and Maven

Chapter 5. m2eclipse Preferences

Chapter 5. m2eclipse Preferences

5.1. Maven Preferences

The ability to adjust the Maven preferences and some Maven options is an important aspect of developing with Maven and m2eclipse offers the ability to tweak these items via the Maven preferences page inside of Eclipse. Typically when using Maven on the command line, such preferences and options are available from files in your ~/.m2 directory and as command line options. m2eclipse provides access to some of the most important preferences and options from the Eclipse IDE. Figure 5.1, “Maven Preferences for Eclipse” shows the Maven preferences page in Eclipse:

Maven Preferences for Eclipse

Figure 5.1. Maven Preferences for Eclipse


The check boxes in the top section provide the ability to:

  • Run Maven in Offline mode, disabling any downloads from remote repositories

  • Enable Debug output in the Maven Console

  • Download Source jars for artifacts from remote Maven repositories

  • Download JavaDoc jars for artifacts from remote Maven repositories

  • Download and Update local indexes for remote repositories on startup

The next section offers a pop-up menu to select which goal you’d like to be executed when a project is imported and when the source folders for a given project are updated. The default goal is named process-resources which copies and process the resources for the project into the destination directory to make the project ready for packaging. Customizing this list of goals can come in handy if you need to run any custom goals which process resources or generate supporting configuration.

If you need help selecting a goal, click the Select... button to see the "Goals" dialog. The dialog on the left-hand side ofFigure 5.2, “Maven Goal Dialogs” shows the Goals dialog with a list of all the phases in the default Maven lifecycle.

Maven Goal Dialogs

Figure 5.2. Maven Goal Dialogs


When you see the Goals dialog for the first time, there's a chance you might be overwhelmed by the number of goals it lists. There are literally hundreds of Maven plugins for everything from generating a database, to running integration tests, to performing static analysis, to generating web services with XFire. There are over two hundred plugins with selectable goals in the Goals dialog, the dialog on the right-hand side ofFigure 5.2, “Maven Goal Dialogs” shows the "Goals" dialog with the Tomcat Maven plugin's goals highlighted. You can always narrow the list of goals shown in this dialog by typing in some text to the search dialog, as you type in text, m2eclipse is going to narrow the list of available goals to goals which contain the text in the search field.

Another Maven preference page is the Maven Installations configuration page shown in Figure 5.3, “Maven Installations Preference Page”:

Maven Installations Preference Page

Figure 5.3. Maven Installations Preference Page


This page allows you to add other Maven installations to the Eclipse environment. If you want to use a different version of Maven with the m2eclipse plugin you can configure multiple installations of Maven from this configuration page, this is very similar to the ability to add more than one Java Virtual Machine to be run inside of Eclipse. An embedded version of the Maven known as the Maven Embedder is already specified. This is what is used to execute Maven inside of Eclipse. If you have another installation of Maven which you would like to use instead of the Maven Embedder, you can add another Maven runtime by clicking on the Add.. button. Figure 5.3, “Maven Installations Preference Page” shows a configuration page that lists the Maven Embedder, Maven 2.0.9, and an installation of Maven 2.1-SNAPSHOT.

The Installations configuration page also allows you to specify the location of the global Maven settings file. If you do not specify the location of this file on this configuration page, Maven will use the default global settings file found in conf/settings.xml of the selected Maven installation. You can also customize the location of your user settings file from the default location of ~/.m2/settings.xml, and you can customize the location of your local Maven repository from the default location of ~/.m2/repository.

Also available in the Eclipse preferences is the ability to enable a decorator named the Maven Version Decorator. This preference provides a given project’s current version on the Eclipse Package Explorer and is shown in Figure 5.4, “Enabling the Maven Version Decorator”.

Enabling the Maven Version Decorator

Figure 5.4. Enabling the Maven Version Decorator


To enable this preference, simply check the Maven Version Decorator option that is highlighted in Figure 5.4, “Enabling the Maven Version Decorator”. If the Maven Version Decorator is not enabled, a project will only list it’s name and relative path in the Package Explorer as shown in Figure 5.5, “Package Explorer without Maven Version Decorator”:

Package Explorer without Maven Version Decorator

Figure 5.5. Package Explorer without Maven Version Decorator


Upon enabling the Maven Version Decorator, the project name will include the current project version as shown in Figure 5.6, “Package Explorer with Maven Version Decorator Enabled”:

Package Explorer with Maven Version Decorator Enabled

Figure 5.6. Package Explorer with Maven Version Decorator Enabled


This is a helpful feature that provides the project version at a glance instead of being required to open the POM to locate the version element.