| By Murali Kashaboina, Geeth Narayanan | Article Rating: |
|
| July 19, 2007 01:15 PM EDT | Reads: |
26,354 |
Next add runtime dependencies in the POM as shown below needed to execute Castor tasks:
<dependencies>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor-codegen-anttask</artifactId>
<version>1.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
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:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<taskdef classname="org.castor.anttask.CastorCodeGenTask" name="castor">
<classpath refid="maven.test.classpath"/>
</taskdef>
<castor types="j2"
warnings="false"
todir="${project.build.directory}/generated-sources/main/java"
bindingfile="${basedir}/src/main/castor/employeeBinding.xml">
<fileset dir="${basedir}/src/main/castor/">
<include name="*.xsd"/>
</fileset>
</castor>
</tasks>
<sourceRoot>${project.build.directory}/generated-sources/main/java</sourceRoot>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
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 project.build.directory. By default the project.build.directory 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 ${project.build.directory}/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.
Conclusion
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.
Published July 19, 2007 Reads 26,354
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Murali Kashaboina
Murali Kashaboina is a lead architect at Ecommerce Technology, United Airlines, Inc. He has more than 10 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.
![]() |
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. |
||||
- Kindle 2 vs Nook
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Windows 7 – Microsoft’s First Step to the Cloud
- Ulitzer Provides a Powerful Social Journalism Platform
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Open Source Mobile Cloud Sync and Push Email
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- US Post Office Hops a Ride on NetSuite’s Cloud
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Building a Drag-and-Drop Shopping Cart with AJAX
- What Is AJAX?
- Google Maps! AJAX-Style Web Development Using ASP.NET
- Flashback to January 2006: Exclusive SYS-CON.TV Interviews on "OpenAjax Alliance" Announcement
- AJAXWorld Conference & Expo to Take Place October 2-4, 2006, at the Santa Clara Convention Center, California
- AJAX Sponsor Webcasts Are Now Available at AJAXWorld Website
- How and Why AJAX, Not Java, Became the Favored Technology for Rich Internet Applications
- "Real-World AJAX" One-Day Seminar Arrives in Silicon Valley
- AJAXWorld University Announces AJAX Developer Bootcamp
- AJAX Support In JadeLiquid WebRenderer v3.1
- Where Are RIA Technologies Headed in 2008?
- Struts Validations Framework Using AJAX






































