| By Murali Kashaboina, Geeth Narayanan | Article Rating: |
|
| July 19, 2007 01:15 PM EDT | Reads: |
26,376 |
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,376
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. |
||||
- IBM Puts Systems Chief on Leave of Absence
- Amazon Web Services Database in the Cloud
- SpringSource Moving to Spring 3.0
- Virtualization Expo Call for Papers Deadline December 15
- Move Over BI, Here Comes PI - Performance Intelligence
- Qt DevDays 2009 - Munich
- Using Ext JS, Servlets, JSON, MySQL and Tomcat on Fedora
- Developing APIs for the Cloud
- Canonical Offers Free Cloudware
- New-Generation Virtualization Technologies with Ultra Low-Cost Endpoints
- The Planet Executive to Speak at Cloud Computing Conference
- Trusting the Cloud
- Oracle-Sun: IBM Reportedly Behind Delay
- The Case for Single-Purpose Services
- IBM Puts Systems Chief on Leave of Absence
- Cloud BI & Amazon VPC
- Cloud-Oriented Switch Start-up Valued at $230M
- The Curious Case of Build Release Management eBook
- Amazon Web Services Database in the Cloud
- Tips for Efficient PaaS Application Design
- Reporting Solutions Using Crystal Reports for Eclipse
- SpringSource Moving to Spring 3.0
- Virtualization Expo Call for Papers Deadline December 15
- Un-Clouding Federal Security Compliance
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- Creating Web Applications with the Eclipse Web Tools Project
- Eclipse Special: Remote Debugging Tomcat & JBoss Apps with Eclipse
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- How to Bring Eclipse 3.1, J2SE 5.0, and Tomcat 5.0 Together
- SYS-CON Webcast: Eclipse IDE for Students, Useful Eclipse Tips & Tricks
- Eclipse: The Story of Web Tools Platform 0.7
- "Eclipse 3.0 is a Great Leap Forward," Says JDJ's Dudney
- Developing an Eclipse BIRT Report Item Extension
- The Top 250 Players in the Cloud Computing Ecosystem




























