Monday, May 18, 2009

Generating Java Beans from XSD Schema

As you probably know, JAXB (Java Architecture for XML Binding) allows to map (marshal/unmarshal) Java Beans to XML representations.
You can also do the opposite: generating Java Beans from XSD Schema.
To do that, there the xjc utility in $JAVA_HOME/bin.
For example:
$ wget http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
$ xjc -p eu.kostia.persistence persistence_1_0.xsd

will generate the classes ObjectFactory, Persistence and PersistenceUnitTransactionType in the package eu.kostia.persistence.

Other useful info here.