tags:

views:

191

answers:

2

The script provided here gave a great way to check if Ant is using Java 6.

<?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>

However, I have good reason to think the next person holding my position may not be a Java programmer and I want to make sure the builds don't fail because of Java 7. Is there any way to pick apart a String or otherwise ask for Java 6 or higher?

A: 

You can use the ContainsRegEx task to do regex matching on the java version string. Otherwise, a lot depends upon what you're guarding with this version check. For example, the javac task has ways of specifying the the JVM version you are targeting the built classes for. So, if you decide not to use the conditional approach in your example, it may depend upon what particular tasks support as far as how they work with different JVM versions.

Rob Heiser
A: 

Beware, the ant.java.version returns the JDK version with which Ant is built till Ant 1.6.5...

girishadat