Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Maven ties together tools for better code management

The Maven tool gives developers a complete picture of their projects

  • Print
  • Feedback

Have you ever been assigned to an existing project where the original programmers are nowhere to be found? Or given source code from a third party and told to fix a bug, only to find there isn't any decent documentation? Avoid some of these resulting headaches by using Maven to generate code-level documentation for your projects. Maven ties together a build management system and various third-party source code analysis tools to help you get your projects out the door faster.

Maven is a project-oriented tool from the Apache Jakarta Project that builds upon Jelly (see the Jelly Website), Ant, and other open source projects to give developers a complete picture of their projects. Maven bundles many open source projects under one umbrella to let developers easily integrate these third-party tools into their build processes. Maven uses plug-ins for various tools, including:

  • Ant for build management
  • JUnit for unit testing
  • Jalopy for formatting source code
  • Checkstyle for validating Java source against a coding standard
  • Sun's javadoc for standard JDK code documentation


For a complete list of Maven's functionalities, check the plug-ins page on the Maven Website.

The Krysalis Centipede project achieves similar goals. An open source build tool based on Ant, Centipede features cents, which are equivalent to plug-ins, and includes many of the same tools as Maven, along with some that Maven omits. Discussions in the Jakarta Project mailing lists have focused on how the two could work together moving forward. If you decide to evaluate Maven, also evaluate Centipede; either one could be appropriate for your project.

In this article, I discuss some key Maven concepts to give you an idea of how Maven works and then launch into a walkthrough of an example project.xml file from a project already using Maven: the Jakarta Project's Torque, which is an object-relational database tool. You should be able to adapt the Torque example for your own use by simply changing some values to match your existing configuration and project setup.

Maven concepts

Maven's central concept is that all code belongs in projects, each one defined by a project descriptor. These projects are either discrete components or a full application that can be built on its own with various dependencies. The descriptor consists of a Project Object Model (POM), which can be a project.xml file, or another storage format such as a database. The XML format for the POM is specified by the maven-project.xsd XML Schema file in your Maven installation's root directory. Generally speaking, copying an example project.xml file from an existing Maven installation and customizing it for your own needs proves easier than creating a new one from scratch.

Maven defines some common goals for projects. Goals resemble Ant targets; you use them to generate source code documentation, compile your application, unit test the compiled project, or run the plug-ins shipped with Maven. To find a project's available goals, run the command maven -g in the directory that contains your project.xml file. This command will return a list of plug-ins and their defined goals. A sample of this output:

  • Print
  • Feedback

Resources