JavaTM Architecture for XML Binding
Sample Applications

Specification Version: 2.0
Reference Implementation (RI) Version: 2.0 EA2

JAXB 2.0: Release Notes | XJC | XJCTask | SchemaGen | schemagenTask | Sample Apps | Changelog
JAXB 1.0.x: Release Notes | Changelog
JAXB RI Extensions: Runtime Properties | XJC Customizations | Develop Plugins
JAXB RI Schema Languages: W3C XML Schema | RELAX NG | DTD
JAXB Community: Homepage | Developer interest list | FAQ

This page summarizes basic use-cases for Java-2-Schema, Schema-2-Java, and lists all of the sample applications that ship with JAXB.

Using the Runtime Binding Framework


Schema-2-Java is the process of compiling one or more schema files into generated Java classes. Here are some of the basic steps for developing an app:

  1. Develop/locate your schema
  2. Annotate the schema with binding customizations if necessary (or place them in an external bindings file)
  3. Compile the schema with the XJC binding compiler
  4. Develop your JAXB client application using the Java content classes generated by the XJC binding compiler along with the javax.xml.bind runtime framework
  5. Set your CLASSPATH to include all of the JAR files
  6. Compile all of your Java sources with javac
  7. Run it!



Java-2-Schema is the process of augmenting existing Java classes with the annotations defined in the javax.xml.bind.annotation package so that the JAXB runtime binding framework is capable of performing the un/marshal operations. Here are the basic steps for developing an app:

  1. Develop your data model in Java
  2. Apply the javax.xml.bind.annotation annotations to control the binding process
  3. Set your CLASSPATH to include all of the JAR files
  4. Compile your data model with javac (Important! make sure that you classpath includes jaxb-xjc.jar before running javac)
  5. The resulting class files will contain your annotations as well other default annotations needed by the JAXB runtime binding framework
  6. Develop your client application that uses the data model and develop the code that uses the JAXB runtime binding framework to persist your data model using the un/marshal operations.
  7. Compile and run your client application!

For more information about this process, see the the Java WSDP Tutorial and the extensive sample application documentation.

Building and Running the Sample Apps with Ant

To run the sample applications using the supplied Ant build.xml files, follow these steps:

For Solaris/Linux:
  1. % <jwsdp.home>/apache-ant/bin/ant -emacs
  2. repeat for each sample app
For WindowsNT/2000/XP:
  1. > <jwsdp.home>\apache-ant\bin\ant -emacs
  2. repeat for each sample app

A few sample applications do not use Ant. For those samples, refer to the included readme.txt files for instructions.

List of Sample Apps

This sample application is very similar to the inline-customize sample application, but illustrates an easier, but not as robust, <jaxb:javaType> customization.
This sample application is identical to the datatypeconverter sample application (formerly SampleApp7) except that the binding customizations are contained in an external binding file.
Another binding customization example that illustrates how to resolve name conflicts. Run "ant fail" first to see the compiler output and then look at binding.xjb to see how the errors were resolved. Running "ant" will use the binding customizations to resolve the name conflicts while compiling the schema.
This sample application demonstrates how to customize the default binding produced by the XJC binding compiler.
samples/j2s-create-marshal  new!
This example illustrates java to schema databinding. It demonstrates marshalling and unmarshalling of JAXB annotated classes. Additionally, it demonstrates how to enable JAXP 1.3 validation at unmarshal time using a schema file generated from the JAXB mapped classes.
This sample application demonstrates how to modify a java content tree and marshal it back to XML data.
In this example, the input document will be unmarshalled a small chunk at a time, instead of unmarshalling the whole document at once.
This sample app demonstrates how a pull-parser (SJSXP) can be used with JAXB to increase the flexibility of processing.
This sample application processes a UBL order instance and writes a report to the screen.
This sample application demonstrates how to unmarshal an instance document into a Java content tree and access data contained within it.
This sample application demonstrates how to enable validation during the unmarshal operations.
This example demonstrates how to use one communication channel (such as a socket) to send multiple XML messages, and how that channel can be combined with JAXB.
This example demonstrates how the behavior of the marshalling process can be customized. In this example, an <?xml-stylesheet ... ?> processing instruction is inserted into the marshalled document.

Sample applications that illustrate JAXB RI vendor extensions.

This example shows how you can use the new JAXB RI Marshaller property "com.sun.xml.bind.characterEscapeHandler" to change the default character escaping behavior.
This sample application illustrate some of the DTD support available in the JAXB RI's extension mode. Please refer to the Vendor Extensions page for more detail.
This sample application illustrates how W3C XML Schema substitution groups are supported in JAXB RI's extension mode. Please refer to the Vendor Extensions page for more detail.
This sample application demonstrates how to use the new JAXB RI Marshaller property "com.sun.xml.bind.namespacePrefixMapper" to customize the namespace prefixes generated during marshalling.
This sample app demonstrates type substitution using the W3C XML Schema Part 0: Primer international purchase order schema.

$Revision: 1.1 $
$Date: 2005/12/13 09:17:30 $