JAXB 2.0 | Tools | JAXB 1.0.x | JAXB RI Extensions | JAXB Community |
The
jaxb-xjc.jar
file contains the
SchemaGenTask.class
file, which allows the schema generator to be invoked from the
Ant build tool. To use
SchemaGenTask
, include the following statement in your
build.xml
file:
<taskdef name="schemagen" classname="com.sun.tools.jxc.SchemaGenTask"> <classpath> <fileset dir="path/to/jaxb/lib" includes="*.jar" /> </classpath> </taskdef>
This maps
SchemaGenTask
to an Ant task named
schemagen
. For detailed examples of using this task, refer to the
build.xml files used by the java to schema
sample applications.
schemagen
supports most of the attributes defined by
the javac task, plus the following parameter attributes.
Attribute | Description | Required |
destdir | Base directory to place the generated schema files | No |
classpath | Works just like the nested <classpath>element | No |
episode | If specified, generate an episode file in the specified name. For more about the episode file, see the schemagen page. | No |
xjc
supports all the nested elements defined by
the javac task,
the following nested element parameters.
Control the file name of the generated schema. This element takes a mandatory namespace attribute and a mandaotry file attribute. When this element is present, the schema document generated for the specified namespace will be placed in the specified file name.
The file name is interpreted as relative to the destdir attribute. In the absence of the destdir attribute, file names are relative to the project base directory. This element can be specified multiple times.
A path-like structure that represents the classpath. If your Java sources/classes depend on other libraries, they need to be available in the classpath.
Generate schema files from source files in the src dir and place them in the build/schemas directory.
<schemagen srcdir="src" destdir="build/schemas">
Compile a portion of the source tree.
<schemagen destdir="build/schemas"> <src path="src" /> <exclude name="Main.java"/> </schemagen>
Set schema file names.
<schemagen srcdir="src" destdir="build/schemas"> <schema namespace="http://myschema.acme.org/common" file="myschema-common.xsd" /> <schema namespace="http://myschema.acme.org/onion" file="myschema-onion.xsd" /> </schemagen>