Change JDK for running <ANT> task from within build xml

Vineet Bhatia picture Vineet Bhatia · Jul 11, 2013 · Viewed 10.3k times · Source

I have build.xml which calls swfbuild.xml. I want parent build.xml to use IBM JDK 1.5 and swfbuild.xml to use Sun JDK 1.6

Is there any option in <ant> task to specify different JDK to use?

I tried setting JAVACMD like below but that doesn't work either

How can I use different JDK for swfbuild.xml?

    <target name="Compile_SWF">
        <exec executable="cmd">
            <env key="JAVACMD" value="C:/Program Files/Java/jdk1.6.0_18" />
        </exec>
        <echo message="Start to Compile SWF content" />
        <ant antfile="swfbuild.xml" target="swf-masterbuild" />
        <exec executable="cmd">
            <env key="JAVACMD" value="C:/IBM/SDP/runtimes/base_v61/java" />
        </exec>
    </target>

Answer

Dave Bartlett picture Dave Bartlett · Jul 11, 2013

In each xml file, you can specify the executable to use inside the javac task. You must include the fork=yes in addition to the executable= parameter.

<javac fork="yes" executable="C:/Program Files/Java/jdk1.7.0_17/bin/javac">