WAS v8.5 > Develop applications > Develop web servicesUse JAXB for XML data binding
Java Architecture for XML Binding (JAXB) is a Java technology that provides an easy and convenient way to map Java classes and XML schema for simplified web services development. JAXB provides the xjc schema compiler, the schemagen schema generator and a runtime framework to support marshalling and unmarshalling of XML documents to and from Java objects. JAXB is an XML-to-Java binding technology that enables transformation between schema and Java objects and between XML instance documents and Java object instances. JAXB technology consists of a runtime API and accompanying tools that simplify access to XML documents. We can use JAXB APIs and tools to establish mappings between Java classes and XML schema. An XML schema defines the data elements and structure of an XML document. JAXB technology provides tooling to enable you to convert your XML documents to and from Java objects. Data stored in an XML document is accessible without the need to understand the XML data structure.
JAXB is the default data binding technology used by the Java API for XML Web Services (JAX-WS) tooling and implementation within this product. We can develop JAXB objects to use within your JAX-WS applications. We can also use JAXB independently of the JAX-WS programming model as a convenient way to leverage the XML data binding technology to manipulate XML within your Java applications.
JAXB is also the default data binding technology used by Service Component Architecture (SCA) applications. JAXB enables the SCA service implementation side and the SCA client reference side to interact with Java objects without worrying about how the data is transformed into and from XML.
This version of the application server supports the JAXB 2.2 specification. JAX-WS 2.2 requires JAXB 2.2 for data binding. JAXB 2.2 provides minor enhancements to its annotations for improved schema generation and better integration with JAX-WS.
The wsimport, wsgen, schemagen and xjc command-line tools are not supported on the z/OS platform. This functionality is provided by the assembly tools provided with WebSphere Application Server running on the z/OS platform. Read about these command-line tools for JAX-WS applications to learn more about these tools.
JAXB provides the xjc schema compiler tool, the schemagen schema generator tool, and a runtime framework. The xjc schema compiler tool enables you to start with an XML schema definition (XSD) to create a set of JavaBeans that map to the elements and types defined in the XSD schema. We can also start with a set of JavaBeans and use the schemagen schema generator tool to create the XML schema. After using either the schema compiler or the schema generator command-line tools, we can convert your XML documents both to and from Java objects and use the resulting Java classes to assemble a web services application.
In addition to using the tools from the command-line, we can invoke these JAXB tools from within the Ant build environments. Use the com.sun.tools.xjc.XJCTask Ant task from within the Ant build environment to invoke the xjc schema compiler tool. Use the com.sun.tools.jxc.SchemaGenTask Ant task from within the Ant build environment to invoke the schemagen schema generator tool. These Ant tasks require the com.ibm.jaxb.tools.jar and the com.ibm.jaxws.tools.jar files be in the classpath.
JAXB annotated classes and artifacts contain all the information the JAXB runtime API needs to process XML instance documents. The JAXB runtime API enables marshaling of JAXB objects to XML files and unmarshaling the XML document back to JAXB class instances. The JAXB binding package, javax.xml.bind, defines the abstract classes and interfaces used directly with content classes. In addition the package defines the marshal and unmarshal APIs.
We can optionally use JAXB binding customizations to override the default generated type mappings. We can customize JAXB bindings using inline annotations in the source schema, or using an external bindings customization file to pass your customizations to the JAXB binding compiler, xjc, to control the Java type mappings. Alternatively, we can add Java annotations to existing Java classes to pass to the schema generator, schemagen, to control the schema or XML type mappings. See the JAXB specification for information regarding binding customization options and Java annotations.
Using JAXB, we can manipulate data objects in the following ways:
- Generate an XML schema from a Java class. Use the schema generator schemagen command to generate an XML schema from Java classes.
- Generate Java classes from an XML schema. Use the schema compiler xjc command to create a set of JAXB-annotated Java classes from an XML schema.
- Marshal and unmarshal XML documents. After the mapping between XML schema and Java classes exists, use the JAXB binding runtime to convert XML instance documents to and from Java objects.
Results
You now have JAXB objects that your Java application can use to manipulate XML data.
Subtopics
- Use JAXB schemagen tooling to generate an XML schema file from a Java class
Use Java Architecture for XML Binding (JAXB) schemagen tooling to generate an XML schema file from Java classes.- Use JAXB xjc tooling to generate JAXB classes from an XML schema file
Use Java Architecture for XML Binding (JAXB) xjc tooling to compile an XML schema file into fully annotated Java classes.- Use the JAXB runtime to marshal and unmarshal XML documents
Use the Java Architecture for XML Binding (JAXB) run time to manipulate XML instance documents.- xjc command for JAXB applications
Use the Java Architecture for XML Binding (JAXB) tools to generate Java classes from an XML schema with the xjc schema compiler tool.- schemagen command for JAXB applications
Use the schema generator tool, schemagen, to generate an XML schema using Java Architecture for XML Binding (JAXB).
Related concepts:
JAXB
Development and assembly tools
Related
Specify bindings in an SCA environment
Reference:
Web services specifications and APIs
Related information:
JAXB 2.2 Reference implementation