This section provides an overview of what jaxb is, and why a developer might want to use it.
It should also mention any large subjects within jaxb, and link out to the related topics. Since the Documentation for jaxb is new, you may need to create initial versions of those related topics.
JAXB can be used to generate classes from an model defined in XSD. It will then be possible to read XML document made against this XSD directly as java instances and inversly save these instances as XML document.
Take the following XSD saved in a file named SimpleModel.xsd
<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://myCorp/schemas/simpleModel" xmlns:simple="http://myCorp/schemas/simpleModel" elementFormDefault="qualified" attributeFormDefault="unqualified"> <complexType name="Person"> <sequence> <element name="FirstName" type="string"/> <element name="LastName" type="string"/> <element name="DateOfBirth" type="dateTime"/> </sequence> </complexType> </schema>
You can use JAXB to generate classes automatically to match this XSD using this command line (provided your JDK's bin folder is on your path)
This will generate a package based on the namespace of your XSD (here mycorp.schemas.simplemodel) with the following classes :
The ObjectFactory is used to create instances of the class(es) that were generated. In some cases this seems like a trivial wrapper around a
The package-info.java contains information about the XSD in general.
All other files are classes derived from the model described in the XSD. Here we only have Person.java since there is only one object in our model.
Using other command line arguments Jaxb and XJC will give you immense power over the generated code. XJC also provide means to use or create plugins to go beyoond and do things like :
And much much more
You can also use other tools to interact with xjc for you, Maven plugins (at least 4 that I know of), Ant task etc. Often times these tools can perform things that would be difficult to get with just the Reference implementation thorugh command line.
The JAXB Reference Implementation (JAXB-RI) has been included with the Java Development Kit since JDK 6 update 3.
Refer to the Unofficial JAXB Guide for additional details on which JAXB-RI version is included with specific versions of the JDK.