| By Murali Kashaboina, Geeth Narayanan | Article Rating: |
|
| July 19, 2007 01:15 PM EDT | Reads: |
26,376 |
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,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



























