logo
header art

Using Maven to Manage Your Projects

June 23, 2005

Configuring Maven for your Project

You can configure a large number of Maven's options through the project.properties file, but if you need to customize your project even further, you can create a maven.xml in the same directory as project.xml. This act is not encouraged, however, because it often undercuts one of the benefits of using Maven: consistent project management behavior and project structure across projects. For that reason, this article will focus on using project.properties to tailor Maven to your project's needs and leave custom maven.xml files for a later date.

For the most part, Maven's defaults are good choices, but there are always a few things that you need to customize for a project. In our sample project.properties file, we override or define properties in 4 distinct categories: documentation site properties, unit-testing properties, tomcat-plugin properties, and war configuration properties.

  • Documentation site properties
    • maven.docs.dest - We set this property a directory that we are serving from our web server so we can easily check out the project documentation.
    • maven.docs.src - We override this property because the default violates Maven's own best practice recommendations on where to place these files; the new value, ${basedir}/src/site/xdoc, is the directory Maven's documentation suggests as the source of your xdocs.
  • Unit-testing properties
    • maven.junit.fork - We set this property to true so that Maven will initiate the unit-testing process in a separate process. As the comments in project.properties indicate, the JUnit plugin for Maven sometimes has errors under a 1.4 JDK unless it is forked off the main Maven process.
  • Tomcat-Plugin properties - these properties are for the Tomcat plugin for Maven instead of Maven itself.
    • maven.tomcat.username - Set this property's value to a username that can access the Tomcat manager application.
    • maven.tomcat.password - Set this property's value to the password for the username we just defined.
    • maven.tomcat.precompile - We set this property to false to tell the Tomcat plugin not to precompile JSPs when deploying the application. In production systems, you would want this property to be true.
    • maven.war.src - We set this property to main/src/main/webapp because that directory contains the files and directory structures we want copied into the root directory of the deployed webapp.

Click here for the complete properties file for the Struts application explained in a separate article this week.

These small examples barely scratch the surface of the properties you can customize for your project. For a more complete reference on the various properties of Maven, please see the Properties Reference on Maven's site.