简体   繁体   中英

future-proofing java version check in ant script

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 ?

请注意,ant.java.version返回构建Ant的JDK版本,直到Ant 1.6.5 ......

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM