<p>I have the problem that an specific step in Ant can only be executed when we have Java 1.5 installed in the build computer.  The task definition uses  uses a jar file that was compiled using 1.5, so running with a 1.4 virtual machine will throw an IncompatibleClassVersion exception.</p>

<p>I have to find a solution meanwhile to have this task working for this specific project that requires 1.4, but a question came to me.  How can I avoid defining this task and executing this optional step if I don't have a specific java version?</p>

<p>I could use the "if" or "unless" tags on the target tag, but those only check if a property is set or not.  I also would like to have a solution that doesn't require extra libraries, but I don't know if the build-in functionality in standard is enough to perform such a task.</p>

The Java version is exposed via the
ant.java.version
property. Use a
condition
to set a property and execute the task only if it is true.
```
```
<?xml version="1.0" encoding="UTF-8"?>

<project name="project" default="default">

    <target name="default" depends="javaCheck" if="isJava6">
        <echo message="Hello, World!" />
    </target>

    <target name="javaCheck">
        <echo message="ant.java.version=${ant.java.version}" />
        <condition property="isJava6">
            <equals arg1="${ant.java.version}" arg2="1.6" />
        </condition>
    </target>

</project>
```
```