CAS Push-Pull-Framework

Using Maven

Setup

Project Structure

Standard Commands

Acknowledgments

References

OODT uses Maven for managing our build environment. Maven is an open source product from the Apache Software Foundation that improves on Ant in the area of build management, which it turn was an improvement on Make. This document describes the use of Maven for Apache OODT build management.

Setup

Maven can be downloaded from the Maven Download page. OODT is using version 2.0 and above. Maven was developed in Java so it will run on the popular platforms (e.g., Windows, Mac OSX, etc.). Beyond making sure the mvn executable is in your path, there is very little setup required.

Maven is based on the concept of a Project Object Model (POM) which is contained in the pom.xml file found at the root of each project. The POM allows Maven to manage a project's build, reporting and documentation. For OODT, much of the default information for managing the projects is contained in a parent POM, which is located in the oodt-core project. So, in order to build any of the other projects (e.g., cas-curator, cas-filemgr, etc.) the parent POM must be downloaded from the OODT Maven repository. The local pom.xml files for each of the projects have been configured to retrieve the parent POM automatically.

Once Maven has been setup, the first step to building a project with Maven is to checkout a project's source code into the developer's work area. See the Using Subversion document for how to check out projects from the CM repository.

Project Structure

In order for default Maven functions to operate properly, there is a suggested project directory structure. The structure is as follows:

/
  src/             Source Code (everything)
    main/            Program Source
      assembly/        Package Descriptor
      java/            Java Source
      resources/       Scripts, Config File, etc.
        ...
    test/            Test Source
      java/
      resources/
        ...
    site/            Site Documentation
      apt/             Docs in APT Format
        index.apt
        ...
      xdoc/            Docs in XDOC Format
        index.xml
        ...
      resources/
        images/
      site.xml         Menu Structure

  target/          Build Results (binaries, docs and packages)
    ...

  LICENSE.txt
  README.txt
  pom.xml          Project Object Model (POM)
      

Standard Commands

There are few standard commands that developers will use on a daily basis and they are related to building and cleaning a project.

Build a Project

Build the project's libraries and executables with the following command:

mvn compile
      

The above command will generate the artifacts in the target/ directory.

Install a Project

Install the project's artifacts locally with the following command:

mvn install
      

Prior to installation, the above command will compile the source code, if necessary, and execute the unit tests. The result of the above command is to install the generated artifacts (e.g. pom, jar, etc.) in the user's local Maven repository ($HOME/.m2/repository/). This is useful when the artifact is a dependency for another project but has yet to be deployed to the Maven repository.

Package a Project

Create the project's distribution package with the following command:

mvn package
      

Prior to package creation, the above command will compile the source code, if necessary, and execute the unit tests. The above command will create the package(s) in the target/ directory.

Build a Project's Web Site

Build the project's web site with the following command:

mvn site
      

The above command will generate the web site in the target/site/ directory. View the site by pointing your web browser at the index.html file within that directory.

Clean a Project

Clean out the project directory of generated artifacts with the following command:

mvn clean
      

The above command will remove the target/ directory and its contents.

Useful Command Arguments

There a couple of useful arguments which can be appended to the commands above to limit the scope of the command.

In order to skip unit test execution, add the following argument:

mvn [command] -Dmaven.test.skip=true
      

The above command is most useful with the install, package and site commands.

When a project has modules defined in the POM, the command can be performed against the top level of the project instead of the modules by adding the following argument:

mvn [command] --non-recursive
      

Acknowledgments

Much of the material in this Maven guide was originally authored by Sean Hardman under the sponsorship of NASA Jet Propulsion Laboratory's Planetary Data System.

References

Here is a list of Maven resources: