background image

JAXB Examples

<< Java-toSchema JAXB Examples | JAXB Compiler Options >>
<< Java-toSchema JAXB Examples | JAXB Compiler Options >>
U
SING THE
E
XAMPLES
15
differences to highlight different JAXB concepts. Note that the Fix Col-
lides example uses
example.xml
rather than
po.xml
.
·
Main.java
is the main Java class for each example.
·
build.xml
is an Ant project file provided for your convenience. Use Ant
to generate, compile, and run the schema-derived JAXB classes automati-
cally. The
build.xml
file varies across the examples.
·
MyDatatypeConverter.java
in the
inline-customize
example is a Java
class used to provide custom datatype conversions.
·
binding.xjb
in the External Customize and Fix Collides examples is an
external binding declarations file that is passed to the JAXB binding com-
piler to customize the default JAXB bindings.
·
example.xsd
in the Fix Collides example is a short schema file that con-
tains deliberate naming conflicts, to show how to resolve such conflicts
with custom JAXB bindings.
Using the Examples
As with all applications that implement schema-derived JAXB classes, as
described above, there are two distinct phases in using JAXB:
1. Generating and compiling JAXB Java classes from an XML source
schema
2. Unmarshalling, validating, processing, and marshalling XML content
In the case of these examples, you perform these steps by using
asant
with the
build.xml
project file included in each example directory.
Configuring and Running the Samples
The
build.xml
file included in each example directory is an asant project file
that, when run, automatically performs the following steps:
1. Updates your
CLASSPATH
to include the necessary schema-derived JAXB
classes.
2. For the Basic and Customize examples, runs the JAXB binding compiler
to generate JAXB Java classes from the XML source schema,
po.xsd
, and
puts the classes in a package named
primer.po
. For the Java-to-Schema
examples runs
schemagen
, the schema generator, to generate XML schema
from the annotated Java classes.