Maven

Although much more than a build tool and environment, the development life-cycle tool for the Java component is Maven. Maven projects are defined and completely described by a single XML file called the "project object model" or generally contained in the common file named pom.xml located at the root directory of the project. Although Maven is a command line tool (mvn), maven provides plug-ins and "goals" for creating IDE specific project files from a pom.xml file. For example, an eclipse IDE project can be created using the maven command:
mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true

This tell maven to create an eclipse project, download source code artifacts for dependencies if available, and download javadoc artifacts for dependencies if available. Conversely many Java IDEs contain their own plug-ins or additions to create project specific files from a pom file.

The Direct Project source tree uses a parent project at the root of the java source tree that contains reference to all sub projects. You can use maven to generate IDE specific project artifacts for all sub projects using the parent pom.xml file, or you can use each projects individual pom file. NOTE: It is recommend to execute a maven build on the parent project the first time you check it out to "install" all required dependencies and resolve inter-project dependencies. See maven site or this link for examples of using multiple module projects.

For a more comprehensive guide to maven, visit the Maven home page.

Project Layout

The typical maven project layout for "jar" artifacts looks like the following (NOTE this is a multiple module project layout):
+-- workspace/
    +-- project1/
    |    +-- pom.xml
    |    +-- src/
    |        +-- main/
    |            +-- java/
    |            +-- resources/
    |        +-- test
    |            +-- java/
    |            +-- resources/
    |            ...
    +-- project2/
    |    +-- pom.xml
    |    +-- src/
    |        +-- main/
    |            +-- java/
    |            +-- resources/
    |        +-- test
    |            +-- java/
    |            +-- resources/
    |
    +-- pom.xml

The pom.xml file at the "workspace" level is the parent pom file and each project contains its own pom file. Java sources are split into categories: main and test. Main contains the sources that make up your code that will go to production/deployment and test contains your unit and functional tests (example: junit test classes). The resources directory contains sources such as image, properties files, or configuration. During the build phases that result in the building of artifacts (package, install, and deploy), maven will move these resources into the proper location of the final artifact

Projects that create different artifact types such as "war" and "ear" files may require additional directories that contain artifact specific source and resource files.

When maven (or your IDE) executes a build, the resulting artifacts typically go into a directory named "target" which resides directly under your projects root directory. NOTE: Target and build artifacts should not be checked into the code repository.

Command Line Build

Although you may use your IDE to create your project end states, ultimately projects will need to be built using the maven command line. There are different stages in the maven build life cycle, but in the end all projects will end by executing the "install" phase (at some point we will get to the "deploy" phase?). To execute the install phase, simply run the following command in the project's root directory that contains the pom.xml file.

mvn clean install

To build the entire source tree, run the maven install command in the root of the java source tree. This will resolve (and download if necessary) all dependencies, compile all sources, run all test cases, generate the artifacts (war, jar, zip, etc), and install the artifacts into the local maven repository.

NOTE:
You will need to install the Java Cryptography Extension Unlimited Strength Jurisdiction Policy Files to successfully run tests and perform a maven build. To install the policy files:
  • Click on the above link and click on "Download JCE 1.4.2 Software"
  • Download and open the file jce_policy-1_4_2_zip.
  • Extract the files local_policy.jar and US_export_policy.jar and place them in your JRE's lib/security (JAVA_HOME/jre/lib/security)directory overwriting the existing files.