Ruben Laguna’s blog

Netbeans: Compile Schemas Into JAXB Classes With XJC Task

To add a XJC task to a Netbeans build.xml you need to add a -pre-compile target to your build.xml. If it’s a netbeans module build.xml then you need to make compile depend on -pre-compile and projectized-common.compile (see example below). For regular Java Applications just define the -pre-compile target as the standard build.xml will call -pre-compile before compile. Then it’s just a matter of defining the <taskdef> with the proper classpath to the jaxb’s jars.

But it’s just simpler to take a look to an example (this one is for a Netbeans module build.xml:

<project name="com.rubenlaguna.en4j.jaxb" default="netbeans" basedir=".">
    <description>Builds, tests, and runs the project com.rubenlaguna.en4j.jaxb.</description>
    <import file="nbproject/build-impl.xml"/>

 <target name="-pre-compile">
        <path id="xjc.classpath">

            <fileset dir="/Applications/NetBeans/NetBeans" includes="*.jar"/>

            <!-- import the JAXB 2.1 library if this task is in java application build.xml. you can't access library classpath from
                     a module's build.xml
            pathelement path="${libs.JAXB21.classpath}"/>
            <pathelement path="${libs.JAXB_21.classpath}"/>

        <taskdef name="xjc" classname="">
            <classpath refid="xjc.classpath"/>

        <xjc destdir="src" package="com.rubenlaguna.en4j.jaxb.generated">
            <schema  dir="src" includes="**/*.xsd"/>
            <produces dir="src/com/rubenlaguna/en4j/jaxb/generated" includes="* impl/*" />
    <target name="compile" depends="-pre-compile,projectized-common.compile"/>