| By Murali Kashaboina, Geeth Narayanan | Article Rating: |
|
| July 19, 2007 01:15 PM EDT | Reads: |
26,356 |
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:
<project>
<parent>
<artifactId>EmployeeInfo</artifactId>
<groupId>com.somecompany</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>xmlBinding</artifactId>
<name>xmlBinding</name>
</project>
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="http://www.w3.org/2001/XMLSchema" xmlns="http://schema.somecompany.com/"
targetNamespace="http://schema.mytestcompany.com/" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="salary" type="xs:string"/>
</xs:sequence>
<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"/>
</xs:complexType>
</xs:element>
</xs:schema>
Next create an employeeBinding.xml Castor binding file in the xmlBinding/src/main/castor directory with the following binding information:
<cbf:binding xmlns:cbf="http://www.castor.org/SourceGenerator/Binding" defaultBindingType="element">
<cbf:package>
<cbf:name>com.somecompany.xmlbinding</cbf:name>
<cbf:namespace>http://schema.somecompany.com/</cbf:namespace>
</cbf:package>
</cbf:binding>
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 http://repository.codehaus.org
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:
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Central Repository</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>codehaus </id>
<name>Codehaus Maven Repository</name>
<url>http://repository.codehaus.org/</url>
</repository>
</repositories>
Published July 19, 2007 Reads 26,356
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








































