CI Tools and Best Practices in the Cloud

Continuous Integration

Subscribe to Continuous Integration: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get Continuous Integration: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Continuous Integration Authors: Elizabeth White, Flint Brenton, Liz McMillan, Pat Romanski, Amit Gupta

Related Topics: Java EE Journal, Apache Web Server Journal

J2EE Journal: Article

An Introduction to Maven - Part II

How to use Maven in product development

The POM for the xmlBinding sub-module has a parent element that refers to the EmployeeInfo module. Also note that the parent EmployeeInfo module refers to the name of the sub-module in the <modules> element. This relationship essentially instructs Maven to look for the parent POM while processing the xmlBinding POM and for all sub-module POMs specified under the <modules> element while processing the EmployeeInfo POM. This sub-module nesting can continue to any level based on the extent of the hierarchical modularization of concerns.

Comparing the two POMs it's evident that both declare the same Junit dependency and specify the same <version> element artifact. It's common that all sub-modules under the one main parent module get released under one version. In this context, it becomes redundant to declare versions in the sub-modules. Maven comes to rescue in such situations by providing a project inheritance model in which sub-modules can inherit build process state attributes from the parent module - group ID, version, dependencies, and other deployment information. Since the xmlBinding module already declares EmployeeInfo as the parent in the POM, to take advantage of project inheritance we just have to make slight changes to the xmlBinding POM. Essentially removing the version, group, and common dependency information from the POM. Below is the modified POM for xmlBinding:


The next step would be to create the XSD and use Castor to generate sources for XML-bound Java classes. Create a new folder in Eclipse called castor under the xmlBinding/src/main directory. Then create the XML schema file employee.xsd under the newly created castor directory. The employee.xsd will contain following schema structure:

<xs:schema version="1.0" xmlns:xs="" xmlns=""
targetNamespace="" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="employee">
             <xs:element name="id" type="xs:string"/>
             <xs:element name="salary" type="xs:string"/>
          <xs:attribute name="firstName" type="xs:string" use="required"/>
          <xs:attribute name="lastName" type="xs:string" use="required"/>
          <xs:attribute name="department" type="xs:string" use="required"/>

Next create an employeeBinding.xml Castor binding file in the xmlBinding/src/main/castor directory with the following binding information:

<cbf:binding xmlns:cbf="" defaultBindingType="element">

Running Ant Tasks
Now it's time to generate Java sources using the Castor binding. There are different ways to do this using Maven. We chose to use a Castor Ant task to generate Java sources to illustrate how Ant tasks can be executed using maven-antrun-plugin. The Maven artifact for the Castor Ant task can be found in the repository. We'll use version 1.1 of the castor-codegen-anttask artifact that's under the org.codehaus.castor group. To use this artifact, we must first add the Codehaus repository information in the POM file as follows:

       <name>Maven Central Repository</name>
       <id>codehaus </id>
       <name>Codehaus Maven Repository</name>

More Stories By Murali Kashaboina

Murali Kashaboina leads Enterprise Architecture at United Airlines, Inc. He has 15+ years of enterprise software development experience utilizing a broad range of technologies, including JEE, CORBA, Tuxedo, and Web services. Murali previously published articles in WLDJ and SilverStream Developer Center. He has master’s degree in mechanical engineering from the University of Dayton, Ohio.

More Stories By Geeth Narayanan

Geeth Narayanan is a senior architect at Ecommerce Technology, United Airlines, Inc. He has 10 years of experience in the IT industry, specializing in solutions using Java EE technologies. Geeth has master's degree in electrical engineering from the University of Toledo, Ohio.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

Most Recent Comments
Brad 10/05/07 04:58:49 PM EDT

On page 2 the Figure 11 cuts off the command that is used.

I think the command is supposed to be "mvn eclipse:eclipse" to generate Eclipse descriptor.

Nazir Khan 09/27/07 05:37:33 AM EDT

This is an amazing intro to maven 2, it has been very beautifully crafted, which starts telling about the internals of maven and how it works on different scenarios and then taking to practicalities of it. Hats off to the guys who made this wonderful work.