1.

How To Generate Java From Xml Schema. Please Show The Example?

Answer»

From command-line:

Windows: %JAXB_HOME%binxjc cars.xsd

UNIX: %JAXB_HOME%/bin/xjc.sh cars.xsd

these write generated files to current directory

From Ant:

 <java jar="${env.JAXB_HOME}/lib/jaxb-xjc.jar" fork="yes">

<arg line="-d ${gen.src.dir} cars.xsd"/>

</java>

Generated Files:

• com/withoutbook/cars directory

Car.java:

  • interface representing the “car” complex type
  • only DESCRIBES get and set methods for car properties

Cars.java:

  • interface representing “cars” global element
  • extends CarsType and javax.xml.bind.Element (just a marker interface)
  • describes no ADDITIONAL methods

CarsType.java:

  • interface representing ANONYMOUS complex type defined inside the “cars” global element
  • provides method to get collection of Car objects (as a java.util.List)

ObjectFactory.java:

  • CLASS used to create objects of the above interface types
  • extends DefaultJAXBContextImpl which extends JAXBContext

bgm.ser:

  • a serialized OBJECT of type com.sun.msv.grammar.trex.TREXGrammar
  • can’t find any documentation on this - don’t know its purpose

jaxb.properties:

  • sets a property that defines the class used to create JAXBContext objects
  • com/withoutbook/cars/impl directory

CarImpl.java:

  • class that implements Car
  • corresponds to the “car” XML Schema complexType

CarsTypeImpl.java:

  • class that implements CarType
  • corresponds to the XML Schema anonymous type inside the “cars” element

CarsImpl.java:

  • class that extends CarsTypeImpl and implements Cars
  • corresponds to the “cars” XML Schema element 

From command-line:

Windows: %JAXB_HOME%binxjc cars.xsd

UNIX: %JAXB_HOME%/bin/xjc.sh cars.xsd

these write generated files to current directory

From Ant:

 <java jar="${env.JAXB_HOME}/lib/jaxb-xjc.jar" fork="yes">

<arg line="-d ${gen.src.dir} cars.xsd"/>

</java>

Generated Files:

• com/withoutbook/cars directory

Car.java:

Cars.java:

CarsType.java:

ObjectFactory.java:

bgm.ser:

jaxb.properties:

CarImpl.java:

CarsTypeImpl.java:

CarsImpl.java:



Discussion

No Comment Found