Invoking an Ant task using a specific JVM

Sometimes you’d like to invoke Ant using a specific JVM, maybe because you want to compile using a well specified JDK implementation.

I solved this problem with a task like this:

<macrodef name="ant-jvm">

   <attribute name="target" />
   <attribute name="jvm" />
   <attribute name="antfile" default="build.xml"/>
   <attribute name="basedir" default="."/>
   <attribute name="args" default="-Dsample.value=xxx"/>
   <attribute name="taskname" default="ant"/>


      <java classname=""

            <pathelement location="${ant.home}/lib/ant-launcher.jar"/>

        <arg value="-buildfile"/>
        <arg file="@{antfile}"/>
        <arg value="@{args}"/>
        <arg value="@{target}"/>
        <arg value="-Dbasedir=@{basedir}"/>



You may use it instead of <ant> task and allows you to specify the jvm to use, something like this:

    <ant-jvm target="-do-ejbdoclet" jvm="${java-1.3}/bin/java" />

Quick and dirty, but it works 🙂


One thought on “Invoking an Ant task using a specific JVM

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s