Search code examples
antxsdjaxbxjc

How can I process multiple xsd schemas using jaxb and the Ant xjc task?


I'm using jaxb to generate java object class from xml schemas within an Ant script like so:

<!-- JAXB compiler task definition -->
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask"
                    classpathref="master-classpath"/>

<!-- Generates the source code from the ff.xsd schema using jaxb -->
<target name="option-generate" description="Generates the source code">
    <mkdir dir="${generated-src.dir}/${option.dir}"/>
    <xjc schema="${config.dir}/ff.xsd" destdir="${generated-src.dir}"
         package="${option.package.name}">
        <arg value="-Xcommons-lang" />
        <arg value="-Xcommons-lang:ToStringStyle=SHORT_PREFIX_STYLE" />
        <produces dir="${generated-src.dir}" includes="**/*.java" />
    </xjc>
</target>

Now, this works brilliantly for one schema (ff.xsd in this example). How can I process several schemas (i.e. several xsd files)?

I tried having a separate ant task per schema, but somehow, this doesn't work as Ant process the first task and then says that the "files are up to date" for the following schemas!


Solution

  • <target name="process-resources" description="Process resources">
        <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask"/>
        <xjc destdir="${basedir}/target/generated-sources/jaxb"
             extension="true">
            <schema dir="src/main/xsd" 
                    includes="JaxbBindings.xsd,CoreTypes.xsd"/>
        </xjc>
    </target>