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

Page 2 of 5

[java] ( NO DEFAULT GOAL )
  compile .................... Compile the project
  jar ........................ Create the deliverable jar file
  jar-resources .............. Copy any resources that must be present in the
                               deployed JAR file
  prepare-filesystem ......... Create the directory structure needed to compile
[javadoc] : Generate API documentation
  generate ................... Generate API documentation
[jdepend] : Generate a dependency report with JDepend
  generate-report ............ Generate a dependency report with JDepend
[junit-report] : Generate a report from the test results


The names in brackets refer to installed Maven plug-ins, with their goals listed underneath. To run the javadoc generate goal, call Maven from the command line with the following syntax: maven javadoc:generate. As it turns out, generate is the javadoc plug-in's default goal, so you can also run it with this command: maven javadoc. However, don't rely on that command for the generate goal.

Additional goals and processing can be defined in the maven.xml file, which is specific to each project. File maven.xml should reside in the same directory as project.xml. Goals originate from the Werken Company's open source werkz project. As mentioned earlier, each goal is identical to an Ant target, except that <goal> replaces the Ant <target> element. The <goal> element has attributes for a name and a description. It can also have a list of prerequisite goals, much like Ant has targets that require other targets to run. The prereqs attribute specifies these goals. Here is an example goal declaration from the Torque 3.0 beta 4 maven.xml:

   <goal name="runtime:prepare" prereqs="java:jar">


Goals can also use the attainGoal command to run a goal directly. An example would look like this:

  <attainGoal name="java:jar">


You can also extend a goal so that pre- or post-processing occurs before or after the goal runs. This proves useful for extending Maven's built-in goals, for example, to archive an old jar file when a new build is created. Instead of using <goal>, use <preGoal> or <postGoal>. These dependent goals use the same syntax internally.

Maven has a strong dependency system for projects as well, although the implementations are quite different. Projects can share dependencies—mostly used for ensuring that every project uses common jar files. For instance, each of your projects may rely on the Jakarta POI jar file; Maven keeps each project current with the latest jar file.

These jar files are retrieved from a repository, which is a directory on a remote Web server that contains all jar files. The jar files are mirrored in a local repository under the Maven installation. The remote repository location is configured in the driver.properties file located in your Maven installation's bin subdirectory. A property called maven.repo.remote takes a comma-separated list of URLs. By default, Maven uses http://www.ibiblio.org/maven as its repository. You will need to set up your own repository with copies of internal jar files, private builds of open source projects, and other resources you might need. Additionally, Maven uses an XML element called repository in the project.xml POM to refer to the source control repository your project uses for storing its source. Maven's source control repository attribute supports CVS (Concurrent Versioning System) and Subversion, an open source Java source control system.

  • Print
  • Feedback

Resources