Using XJC with Ant

jaxb-xjc.jar contains the XJC ant task, which allows XJC to be invoked from the Ant build tool. To use the XJC task, you need to include the following statement in your build.xml:


<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
  <classpath>
    <fileset dir="jaxb-ri/lib">
      <include names="*.jar"/>
    </fileset>
  </classpath>
</taskdef>

If XJC is already available in your classpath, you can just write:


<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask"/>

Synopsis

The XJC task supports the following parameter attributes.

Attribute Description Required
schema A schema file to be compiled This or nested <schema> elements are required.
package If specified, generated code will be placed under this Java package. This option is useful only when neither the schema nor the external binding file specifies one. No
target Generated code will be written under this directory. If you specify target="abc/def" and package="org.acme", then files are generated to abc/def/org/acme. Yes
readonly Generate Java source files in the read-only mode if true is specified. false by default. No

Following nested element parameters are supported as well.

schema

To compile more than one schema at the same time, use this nested file set.

Examples


<xjc schema="src/myschema.xsd" target="src" package="org.acme.foo"/>

Compiles myschema.xsd and places the generated files under src/org/acme/foo.


<xjc target="src">
  <schema  dir="src" includes="*.xsd"/>
</xjc>

Compiles all XML Schema files in the src directory places the generated files under the appropriate packages in the src directory. This example doesn't search sub-directories of the src directory to look for schema files.