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: Jason Bloomberg, Yeshim Deniz, Elizabeth White, Pat Romanski, Liz McMillan

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

Next add runtime dependencies in the POM as shown below needed to execute Castor tasks:



Below is the core part where we'll add maven-antrun-plugin, which can be used to execute Ant tasks. The plug-in can be added to the POM as shown below:

             <taskdef classname="org.castor.anttask.CastorCodeGenTask" name="castor">
               <classpath refid="maven.test.classpath"/>
                 <castor types="j2"

             <fileset dir="${basedir}/src/main/castor/">
               <include name="*.xsd"/>

As evident from the POM snippet above, the plug-in is configured to execute the run goal of the plug-in when the generate-sources lifecycle phase is triggered. The maven-antrun-plugin will execute any Ant tasks declared in the configuration/tasks element. In this case we define an Ant task named castor using the org.castor.anttask.CastorCodeGenTask Java class. Note that we refer to the maven.test.classpath provided by Maven as a runtime property. This particular classpath will contain all the dependencies including test dependencies. While invoking the declared castor task, we refer to some of the other properties provided by Maven such as the By default the will point to the currentProjectModule/target directory where project outputs such as classes and reports are usually stored. Note that the POM state information is accessible in the form of runtime properties. For example, the version of the current artifact can be referred to the project.version property. And note that the generated source files will be put in the ${}/generated-sources/main/java directory and by specifying the <sourceRoot>' element under the plug-in configuration, we tell the Maven plug-in to add a generated source directory as a project source directory. To generate sources right-click on the xmlBinding POM file in Eclipse and then in the Run As options select Maven 2 generate-sources as shown in Figure 19.

Eclipse will run a generate-sources lifecycle phase on the xmlBinding POM. The Eclipse console output from the Maven execution will be as shown in Figure 20.

The Castor-generated source files can be found under the target directory and when Maven sources are updated using Maven option in the right-click menu, Eclipse should display the generated source directory in the package explorer as shown in Figure 21.

To deploy the xmlBinding JAR artifact to the local repository for the first time right-click on the parent EmployeeInfo module's POM file in Eclipse and then in Run As options select Maven 2 install. This will run the Maven lifecycle phases till the install phases for the parent and for all the child modules. Maven builds the JAR artifact and copies it over to the local repository along with the POM information as shown in the Figure 22.

In this installment of the article, we have shown how to download and install Maven 2, how to install Maven 2 plugin for Eclipse and how to go about setting up a project directory structure using Maven 2. We used a simple use case of displaying employee details on the web given an employee ID but deliberately made the design a bit complex by introducing design concepts such as XML binding, EJBs, and JCA connectors to illustrate a few of the many features offered by Maven. In the final installment of the article, we will discuss remaining modules from the example application and will illustrate how Maven 2 helps in accomplishing typical development tasks in a fairly easy manner that otherwise would demand significant time and effort to accomplish.

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)

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.