views:

2145

answers:

2

Hi All,

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" depends="">
    <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 xzd 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 !

Any idea ?

Cheers David

+4  A: 
  <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>
maximdim
ah great, exactly what I needed.Thanks !
DavidM
A: 
<target name="generate-jaxb-code">
    <java classname="com.sun.tools.internal.xjc.XJCFacade">
            <arg value="-p" />
            <arg value="com.example"/>
            <arg value="xsd/sample.xsd" />
    </java>
</target>

works with the JAXB that is part of JDK 6 seems that the ANT task only ships with the downloadable JAXB but since JAXB is part of the JDK its probably not a good idea to take the latest release of the JAXB and add to the classpath of the JDK since that means you probably need to mess around with classloader settings, to pickup the downloaded version rather than the version within the JDK.

ams