>> > 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 can 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 the 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 initializer. 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; Class.forName("java.lang.Void"); javaVersion = JAVA_1_1; javaVersionNumber++; .... } catch (Throwable t) { .... Jan [1] http://svn.apache.org/viewcvs.cgi/*checkout*/ant/core/trunk/build.xml?co ntent-type=text%2Fplain [2] http://svn.apache.org/viewcvs.cgi/*checkout*/ant/core/trunk/src/main/org /apache/tools/ant/util/JavaEnvUtils.java?rev=278136&content-type=text%2F plain --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]