Next: Platform Notes Up: XML Enhancements to Java™ Previous: Runtime Options


Apache Ant Integration

XJ programs can also be compiled from Apache Ant [Apache Software Foundation 2005] build.xml scripts by using the provided <xjc> task. Due to a bug in earlier versions of Ant, the <xjc> task requires Ant version 1.6.5 or later. Just as xjc compiles .java files, the <xjc> task can be used as a replacement for the <javac> task (except that it also compiles .xj programs). Below is a sample invocation of the <xjc> task to compile all files in a given directory:

    <xjc destdir="${build}" debug="on" verbose="on"
         includes="${src}/**.java,${src}/**.xj">
        <src location="${src}"/>
        <classpath refid="standard.classpath"/>
    </xjc>

Before the <xjc> task can be used, it needs to be defined. This is normally done by including the provided antlib file. Below is an example build.xml target, <declarexjctask> that defines the <xjc> task:

<target name="declarexjctask">
    <taskdef resource="com/ibm/xj/antlib.xml" onerror="fail"
             classpathref="standard.classpath"/>
    <property name="xjc.declared" value="true"/>
</target>

The antlib file is included in the distribution as part of the xj-ant.jar file, which needs to be in the classpath. Any target that uses the <xjc> task needs to depend on the <declarexjctask> target above. For convenience, upon successful declaration of the <xjc> task, the above target also defines the xjc.declared property, which the dependent targets could be made conditional upon:

<path id="standard.classpath">
    <pathelement location="${build}"/>
    ...
    <fileset dir="${xjdir}/lib">
        <include name="xj-ant.jar"/>
        <include name="xj-runtime.jar"/>
        <include name="xj-xpath.jar"/>
    </fileset>
</path>
...
<target name="compile" depends="init,declarexjctask" if="xjc.declared">
    <xjc ...>...</xjc>
    ...
</target>

The XJ distribution includes a sample build.xml file in the samples directory.



Next: Platform Notes Up: XML Enhancements to Java™ Previous: Runtime Options
XJ Group 2005-09-13