Package org.apache.tools.ant.util
Class JavaEnvUtils
java.lang.Object
org.apache.tools.ant.util.JavaEnvUtils
A set of helper methods related to locating executables or checking
conditions of a given Java installation.
Starting with Java 10 we've stopped adding JAVA_
and VERSION_
attributes for new major version numbers
of the JVM.
- Since:
- Ant 1.5
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Version constant for Java 1.0static final String
Version constant for Java 1.1static final String
Version constant for Java 1.2static final String
Version constant for Java 1.3static final String
Version constant for Java 1.4static final String
Version constant for Java 1.5static final String
Version constant for Java 1.6static final String
Version constant for Java 1.7static final String
Version constant for Java 1.8static final String
Deprecated.use #JAVA_9 insteadstatic final String
Version constant for Java 10static final String
Version constant for Java 11static final String
Version constant for Java 12static final String
Version constant for Java 9static final int
Number Version constant for Java 1.0static final int
Number Version constant for Java 1.1static final int
Number Version constant for Java 1.2static final int
Number Version constant for Java 1.3static final int
Number Version constant for Java 1.4static final int
Number Version constant for Java 1.5static final int
Number Version constant for Java 1.6static final int
Number Version constant for Java 1.7static final int
Number Version constant for Java 1.8static final int
Deprecated.use #VERSION_9 insteadstatic final int
Number Version constant for Java 10static final int
Number Version constant for Java 11static final int
Number Version constant for Java 12static final int
Number Version constant for Java 9 -
Method Summary
Modifier and TypeMethodDescriptionstatic File
createVmsJavaOptionFile
(String[] cmds) Writes the command into a temporary DCL script and returns the corresponding File object.static String
Return the value of ${java.home}static String
Returns the version of Java this class is running under.static int
Deprecated.use #getParsedJavaVersion insteadstatic String
getJdkExecutable
(String command) Finds an executable that is part of a JDK installation based on the java.home system property.static String
getJreExecutable
(String command) Finds an executable that is part of a JRE installation based on the java.home system property.get a vector of strings of packages built into that platforms runtime jar(s)Testing helper method; kept here for unification of changes.static DeweyDecimal
Returns the version of Java this class is running under.static boolean
Checks whether the current VM is Apache Harmony.static boolean
isAtLeastJavaVersion
(String version) Compares the current Java version to the passed in String - assumes the argument is one of the constants defined in this class.static boolean
Checks whether the current Java VM is GNU Classpathstatic boolean
isGij()
Checks whether the current Java VM is the GNU interpreter gij or we are running in a gcj precompiled binary.static boolean
isJavaVersion
(String version) Compares the current Java version to the passed in String - assumes the argument is one of the constants defined in this class.static boolean
isKaffe()
Checks whether the current Java VM is Kaffe.
-
Field Details
-
JAVA_1_0
-
VERSION_1_0
public static final int VERSION_1_0Number Version constant for Java 1.0- See Also:
-
JAVA_1_1
-
VERSION_1_1
public static final int VERSION_1_1Number Version constant for Java 1.1- See Also:
-
JAVA_1_2
-
VERSION_1_2
public static final int VERSION_1_2Number Version constant for Java 1.2- See Also:
-
JAVA_1_3
-
VERSION_1_3
public static final int VERSION_1_3Number Version constant for Java 1.3- See Also:
-
JAVA_1_4
-
VERSION_1_4
public static final int VERSION_1_4Number Version constant for Java 1.4- See Also:
-
JAVA_1_5
-
VERSION_1_5
public static final int VERSION_1_5Number Version constant for Java 1.5- See Also:
-
JAVA_1_6
-
VERSION_1_6
public static final int VERSION_1_6Number Version constant for Java 1.6- See Also:
-
JAVA_1_7
-
VERSION_1_7
public static final int VERSION_1_7Number Version constant for Java 1.7- See Also:
-
JAVA_1_8
-
VERSION_1_8
public static final int VERSION_1_8Number Version constant for Java 1.8- See Also:
-
JAVA_1_9
Deprecated.use #JAVA_9 insteadVersion constant for Java 1.9- See Also:
-
VERSION_1_9
Deprecated.use #VERSION_9 insteadNumber Version constant for Java 1.9- See Also:
-
JAVA_9
-
VERSION_9
public static final int VERSION_9Number Version constant for Java 9- Since:
- Ant 1.9.8
- See Also:
-
JAVA_10
-
VERSION_10
public static final int VERSION_10Number Version constant for Java 10- Since:
- Ant 1.10.7
- See Also:
-
JAVA_11
-
VERSION_11
public static final int VERSION_11Number Version constant for Java 11- Since:
- Ant 1.10.7
- See Also:
-
JAVA_12
-
VERSION_12
public static final int VERSION_12Number Version constant for Java 12- Since:
- Ant 1.10.7
- See Also:
-
-
Method Details
-
getJavaVersion
Returns the version of Java this class is running under.Up until Java 8 Java version numbers were 1.VERSION - e.g. 1.8.x for Java 8, starting with Java 9 it became 9.x.
- Returns:
- the version of Java as a String, e.g. "1.6" or "9"
-
getJavaVersionNumber
Deprecated.use #getParsedJavaVersion insteadReturns the version of Java this class is running under.This number can be used for comparisons.
- Returns:
- the version of Java as a number 10x the major/minor, e.g Java1.5 has a value of 15 and Java9 the value 90 - major will be 1 for all versions of Java prior to Java 9, minor will be 0 for all versions of Java starting with Java 9.
-
getParsedJavaVersion
Returns the version of Java this class is running under.This number can be used for comparisons.
- Returns:
- the version of Java as major.minor, e.g Java1.5 has a value of 1.5 and Java9 the value 9 - major will be 1 for all versions of Java prior to Java 9, minor will be 0 for all versions of Java starting with Java 9.
-
isJavaVersion
Compares the current Java version to the passed in String - assumes the argument is one of the constants defined in this class. Note that Ant now requires JDK 1.8+ soJAVA_1_0
throughJAVA_1_7
need no longer be tested for.- Parameters:
version
- the version to check against the current version.- Returns:
- true if the version of Java is the same as the given version.
- Since:
- Ant 1.5
-
isAtLeastJavaVersion
Compares the current Java version to the passed in String - assumes the argument is one of the constants defined in this class. Note that Ant now requires JDK 1.8+ soJAVA_1_0
throughJAVA_1_7
need no longer be tested for.- Parameters:
version
- the version to check against the current version.- Returns:
- true if the version of Java is the same or higher than the given version.
- Since:
- Ant 1.7
-
isKaffe
public static boolean isKaffe()Checks whether the current Java VM is Kaffe.- Returns:
- true if the current Java VM is Kaffe.
- Since:
- Ant 1.6.3
- See Also:
-
isClasspathBased
public static boolean isClasspathBased()Checks whether the current Java VM is GNU Classpath- Returns:
- true if the version of Java is GNU Classpath
- Since:
- Ant 1.9.1
-
isGij
public static boolean isGij()Checks whether the current Java VM is the GNU interpreter gij or we are running in a gcj precompiled binary.- Returns:
- true if the current Java VM is gcj/gij.
- Since:
- Ant 1.8.2
-
isApacheHarmony
public static boolean isApacheHarmony()Checks whether the current VM is Apache Harmony.- Returns:
- true if the current VM is Apache Harmony.
- Since:
- Ant 1.8.2
-
getJreExecutable
Finds an executable that is part of a JRE installation based on the java.home system property.java
,keytool
,policytool
,orbd
,rmid
,rmiregistry
,servertool
andtnameserv
are JRE executables on Sun based JRE's.You typically find them in
JAVA_HOME/jre/bin
ifJAVA_HOME
points to your JDK installation. JDK < 1.2 has them in the same directory as the JDK executables.- Parameters:
command
- the java executable to find.- Returns:
- the path to the command.
- Since:
- Ant 1.5
-
getJdkExecutable
Finds an executable that is part of a JDK installation based on the java.home system property.You typically find them in
JAVA_HOME/bin
ifJAVA_HOME
points to your JDK installation.- Parameters:
command
- the java executable to find.- Returns:
- the path to the command.
- Since:
- Ant 1.5
-
getJrePackageTestCases
-
getJrePackages
-
createVmsJavaOptionFile
Writes the command into a temporary DCL script and returns the corresponding File object. It is the job of the caller to delete the file on exit.- Parameters:
cmds
- the command.- Returns:
- the file containing the command.
- Throws:
IOException
- if there is an error writing to the file.
-
getJavaHome
-