ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject AW: Real meaning of javac target/source attributes
Date Fri, 17 Feb 2006 14:32:08 GMT
>> > There are other ways to accomplish this (and Ant itself 
>makes use of 
>> > some of those techniques) but you can't rely on those being 100% 
>> > safe.
>> Such as?  I'm really curious.
>The usual tricks, like checking for the existence of a class 
>known to be introduced in a given JRE version, looking at 
>various system properties, etc. 
>I suppose you could say that those techniques are more about 
>tolerating different versions of the JRE at runtime because 
>you still have to know in advance what function was introduced 
>when. They can be useful though, especially in cases where you 
>have a problem that can be solved in all JRE versions, but can 
>be solved better in later JRE versions because of new APIs 
>available in the later version.

Ant does that for compiling newer features. Ants guideline is that it
be compiled against Java 1.2. So you could build it on 1.2 and it works.
But there are some additional tasks which needs newer Java versions.
They are
handled same as tasks relying on external libraries. (The enhancement of
newer JDK against 1.2 is the external lib :-) 

Ants buildfile [1] checks for the existance of several classes
introduced in the
jdk versions. See the target "check_for_optional_packages"
    <available property="jdk1.3+" classname="java.lang.StrictMath"/>
    <available property="jdk1.4+" classname="java.lang.CharSequence"/>
    <available property="jdk1.5+" classname="java.lang.Readable"/>

The JavaEnvUtil [2] class of Ant uses the same technique in its static
    static {
        // Determine the Java version by looking at available classes
        // java.lang.Readable was introduced in JDK 1.5
        // java.lang.CharSequence was introduced in JDK 1.4
        // java.lang.StrictMath was introduced in JDK 1.3
        // java.lang.ThreadLocal was introduced in JDK 1.2
        // java.lang.Void was introduced in JDK 1.1
        // Count up version until a NoClassDefFoundError ends the try

        try {
            javaVersion = JAVA_1_0;
            javaVersionNumber = 10;
            javaVersion = JAVA_1_1;
        } catch (Throwable t) {



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message