schemagen command for JAXB applications
Use the schema generator tool, schemagen, to generate an XML schema using JAXB.
Use JAXB APIs and tools to establish mappings between an XML schema and Java classes. XML schemas describe the data elements and relationships in an XML document. After a data mapping or binding exists, we can convert XML documents to and from Java objects. We can now access data stored in an XML document without the need to understand the data structure.
We can generate a schema file from Java classes using the schemagen schema generator tool to create the XML schema. After the mapping between XML schema and Java classes exists, XML instance documents can be converted to and from Java objects through the use of the JAXB binding runtime API. The resulting Java classes contain all the necessary information that the JAXB run time requires to parse the XML for marshaling and unmarshaling. We can use the JAXB classes within JAX-WS applications or in the non-JAX-WS Java applications for processing XML data.
Supported configurations: 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.
Best practice: WebSphere Application Server provides JAX-WS and JAXB tooling. The wsimport, wsgen, schemagen and xjc command-line tools are located in the app_server_root\bin\ directory in full profile. The wsimport and wsgen commands are located in the app_server_root\jaxws\bin\ directory in Liberty profile. The xjc and schemagen commands are located in the app_server_root\jaxb\bin\ directory in Liberty profile. Similar tooling is provided by the Java SE Development Kit (JDK) 6. On some occasions, the artifacts generated by both the tooling provided by WebSphere Application Server and the JDK support the same levels of the specifications. In general, the artifacts generated by the JDK tools are portable across other compliant runtime environments. However, it is a best practice to use the tools provided with this product to achieve seamless integration within the WAS environment and to take advantage of the features that may be only supported in WebSphere Application Server. To take advantage of JAX-WS and JAXB V2.2 tooling, use the tools provided with the application server that are located in the app_server_root\bin\ directory.bprac
When running the schemagen tool to process JavaBeans, the schema generator will not automatically process the @XmlSchema annotations from existing package-info.class files to derive targetNamespaces. To assure that the schemagen tool processes namespace values correctly, use one of the following methods:
- Explicitly specify the package-info.java source file in the schemagen invocation; for example:
schemagen sample.Address sample\package-info.java
- Use the @XmlType annotation namespace attribute within the JavaBeans to specify a namespace; for example:
@XmlType(namespace="http://myNameSpace") public class Address {...}gotcha
In addition to using the schemagen tool from the command line, we can invoke this JAXB tool from within the Ant build environments. Use the com.sun.tools.jxc.SchemaGenTask Ant task from within the Ant build environment to invoke the schemagen schema generator tool. To function properly, this Ant task requires that you invoke Ant using the ws_ant script.
Syntax
The command-line syntax is:
app_server_root\bin\schemagen.bat [options] <java_files>
app_server_root/bin/schemagen.sh [options] <java_files>
(iseries)
app_server_root/bin/schemagen [options] <java_files>
Parameters
The following parameters are optional for the schemagen command:
- -classpath <path>
- Location of the Java source or class files.
- -cp <path>
- Location of the Java source or class files.
- -d <path>
- Specifies where to place the processor and the generated Java class files.
- -episode<file_name>
- Specifies to generate an episode file for separate compilation.
- -encoding <encoding>
- Specifies to use encoding when invoking the -apt or -javac tool. This property is applicable for JAXB 2.2 and later.
- -help
- Displays the help menu.
- -version
- Prints the version information. If we specify this option, only the version information is output and typical command processing does not occur.
Related concepts
Development and assembly tools
Related tasks
Use JAXB for XML data binding
Related information:
Web services specifications and APIs