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 3 of 5

Use Maven to build your project

Once you have your project.xml and maven.xml files set up for your project, just run Maven from the command line in the directory that has those files. Maven will download the appropriate jar files to its local repository. Maven then creates a target directory (called target) for its output. Maven uses javac to compile the source directory's contents to a subdirectory called classes under the target directory. Maven then fires off the unit tests configured under the build element in project.xml. If those tests succeed, Maven will create a jar file with the project's name and version in the target directory.

Use Maven to create documentation for your project

Maven can also generate an impressive Website for your project. Run the site:generate goal for your project with this command:

 maven site:generate


Maven will create a new subdirectory under target called docs. Open index.html in your favorite Web browser and surf around. Maven integrates project information, Javadocs, unit-test information, source code cross referencing, a coding style check, metrics, and more into a single static generated Website—no CGI, servlets, or anything else necessary.

Maven gets its look and feel for the generated Website from the XDoc plug-in. This plug-in is located in the maven/plugins/maven-xdoc-plugin-1.1/ directory, and you can modify its CSS (Cascading Stylesheets), images, and XML templates. Since the Website should be used internally anyway, you won't find many reasons for modifying it, plus you would have to move any changes to a new version of Maven when you upgrade.

Download and install Maven

You can download Maven from the Maven download page, which also features installation instructions. Because Maven's installation process is constantly improving, I won't discuss it here. As of this writing, Maven remains at the 1.0 beta 6 version, and the released version's installation procedure might differ.

Example: Torque 3.0 beta 4

The Jakarta Project's Torque object-relational mapping tool uses Maven in its latest release for building and creating the Website on the Jakarta Project's site. To show you an example project, I'll walk you through Torque's project.xml. You'll find this file in the source code that can be downloaded from the Jakarta Project; you'll find the generated documentation on the Torque project page.

The project.xml included with Torque is used only by Maven and only by a developer building Torque from source or creating documentation. Developers using Torque for their own projects don't need that file. To create a project.xml file, start with a root element of <project>:

 <?xml version="1.0" encoding="UTF-8"?>
<project>


The <pomVersion> element, illustrated below, identifies the POM version used when this project.xml was created. You shouldn't need to change the version. Future Maven versions will have larger numbers.

   <pomVersion>3</pomVersion>


The <id> element, shown below, is Maven's naming convention; for example, you can use it to name jar files. You append the current tool version to the <id> tag's value—Torque's jar file is named torque-3.0-b4.jar. The <name> is a longer version of <id>.

    <id >torque </id >
   <name >jakarta-turbine-torque </name >
   <currentVersion >3.0-b4 </currentVersion >


The organization refers to the project developers. Replace that element with your company's name, homepage, and a logo URL that can be used as an <img> HTML tag's src attribute:

    <organization >
     <name >Apache Software Foundation </name >
     <url >http://jakarta.apache.org/ </url >
     <logo >/images/jakarta-logo-blue.gif </logo >
   </organization >


You use the inception year for copyright notices in the Javadoc:

    <inceptionYear >2000 </inceptionYear >


All of Torque's code should be under this package:

    <package >org.apache.torque </package >


This is the URL for Torque's logo; it resembles the organization's logo described above:

    <logo >/images/blue-logo.gif </logo >


Gump is another Jakarta Project build tool that helps build many interdependent projects. You probably aren't using it, so you can leave this element out:

    <!-- Gump integration -- >
   <gumpRepositoryId >jakarta </gumpRepositoryId >


This description will go on the front page of the Website generated with Maven:

    <description >Torque is a persistence layer. </description >


A brief description of the project:

    <shortDescription >Persistence Layer </shortDescription >


The <url> element is the project's homepage:

    <url >http://jakarta.apache.org/turbine/torque/ </url >


Include a link to your bug tracker if it's Web-based:

   <issueTrackingUrl >http://issues.apache.org/scarab/servlet/scarab/ </issueTrackingUrl >


Maven can optionally deploy the generated Website to another Web server, using the site:deploy goal. Set the values of the XML elements below to your Web server's name and filesystem path:

    <siteAddress >jakarta.apache.org </siteAddress >
   <siteDirectory >/www/jakarta.apache.org/turbine/torque/ </siteDirectory >


Similar to the above code, Maven can publish the entire distribution it creates to the Web server using the dist:deploy goal:

   <distributionDirectory >/www/jakarta.apache.org/builds/jakarta-turbine-torque/ </distributionDirectory >


Below is the source control repository I discussed above. It only works with CVS. Modify this code to use your CVS connection string if you have one. The URL proves useful if you run WebCVS or another Web-accessible CVS server; developers that visit your site don't have to load CVS or a GUI (graphical user interface) to get one or two source code files.

    <repository >
 <connection >scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-turbine-torque </connection >
     <url >http://cvs.apache.org/viewcvs/jakarta-turbine-torque/ </url >
   </repository >


Maven creates a mailing-lists page for your documentation. Modify the value of the mailingList XML elements below, if it has any. The <subscribe> and <unsubscribe> elements should be email addresses monitored by the list-manager software. The <archive> element can point to the URL for your mailing list's back emails.

    <mailingLists >
     <mailingList >
       <name >Torque User List </name >
 <subscribe >turbine-torque-user-subscribe@jakarta.apache.org </subscribe >
 <unsubscribe >turbine-torque-user-unsubscribe@jakarta.apache.org </unsubscribe >
 <archive >http://archives.apache.org/eyebrowse/SummarizeList?listName=turbine-torque-user@jakarta.apache.org </archive >
     </mailingList >
     <mailingList >
       <name >Torque Developer List </name >
      
 <subscribe >turbine-torque-dev-subscribe@jakarta.apache.org </subscribe >
 <unsubscribe >turbine-torque-dev-unsubscribe@jakarta.apache.org </unsubscribe >
 <archive >http://archives.apache.org/eyebrowse/SummarizeList?listName=turbine-torque-dev@jakarta.apache.org </archive >
     </mailingList >
   </mailingLists >


Maven also creates an HTML page that displays the project developers' names and emails. This can prove extremely useful in big companies where development teams are scattered across locations. For smaller development groups, this page probably isn't as important:

  • Print
  • Feedback

Resources