Sunday, September 19, 2010

Generating Java POJO from XSD schema - JAXB and CASTOR

It is a contribution from Parthiban Rajasekaran

Generate Java Files using JAXB
1. Download latest JAXB Binary from https://jaxb.dev.java.net [latest as of now can be downloaded from https://jaxb.dev.java.net/2.2/JAXB2_20091104.jar] and execute this jar to get the JAXB package
2. Create JAXB_HOME with the jaxb extracted location, for example D:\Personal\Downloaded\Sun API\JAXB\jaxb-ri-20091104
3. Append %JAXB_HOME%\bin in the path system variable
4. Execute xjc command from the dtd or xsd location to generate java files
a. To create java from dtd – xjc -d -p -dtd
b. To create java from xsd – xjc -d -p

Hint: Convert DTD to XML - http://www.hitsw.com/xml_utilites/

Generate Java Files from XSD using Castor

set classpath=castor-1.3-codegen.jar;castor-1.3-xml.jar;castor-1.3-xml-schema.jar;castor-1.3-core.jar;commons-logging-1.1.1.jar;%CLASSPATH%;

java org.exolab.castor.builder.SourceGeneratorMain -i message.xsd -package com.bt.hqn.creditclient.buynet.integration.cbean