Top Description Fields Constructors Methods
org.apache.tools.ant.util

public final Class JavaEnvUtils

extends Object
Class Inheritance
Imports
java.io.BufferedWriter, .File, .FileWriter, .IOException, java.util.Vector, org.apache.tools.ant.taskdefs.condition.Os

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 TypeField and Description
private static boolean
classpathDetected

Whether this is a GNU Classpath based VM

private static final FileUtils
FILE_UTILS

FileUtils instance for path normalization

private static boolean
gijDetected

Whether this is the GNU VM (gcj/gij)

private static boolean
harmonyDetected

Whether this is Apache Harmony

private static final boolean
IS_AIX

Are we on AIX

private static final boolean
IS_DOS

Are we on a DOS-based system

private static final boolean
IS_NETWARE

Are we on Novell NetWare

public static final String
JAVA_10

Version constant for Java 10

public static final String
JAVA_11

Version constant for Java 11

public static final String
JAVA_12

Version constant for Java 12

public static final String
JAVA_1_0

Version constant for Java 1.0

public static final String
JAVA_1_1

Version constant for Java 1.1

public static final String
JAVA_1_2

Version constant for Java 1.2

public static final String
JAVA_1_3

Version constant for Java 1.3

public static final String
JAVA_1_4

Version constant for Java 1.4

public static final String
JAVA_1_5

Version constant for Java 1.5

public static final String
JAVA_1_6

Version constant for Java 1.6

public static final String
JAVA_1_7

Version constant for Java 1.7

public static final String
JAVA_1_8

Version constant for Java 1.8

public static final String
JAVA_1_9

Version constant for Java 1.9

public static final String
JAVA_9

Version constant for Java 9

private static final String
JAVA_HOME

shortcut for System.getProperty("java.home")

private static String
javaVersion

Version of currently running VM.

private static int
javaVersionNumber

floating version of the JVM

private static Vector<String>
jrePackages

array of packages in the runtime

private static boolean
kaffeDetected

Whether this is the Kaffe VM

private static final DeweyDecimal
parsedJavaVersion

Version of currently running VM.

public static final int
VERSION_10

Number Version constant for Java 10

public static final int
VERSION_11

Number Version constant for Java 11

public static final int
VERSION_12

Number Version constant for Java 12

public static final int
VERSION_1_0

Number Version constant for Java 1.0

public static final int
VERSION_1_1

Number Version constant for Java 1.1

public static final int
VERSION_1_2

Number Version constant for Java 1.2

public static final int
VERSION_1_3

Number Version constant for Java 1.3

public static final int
VERSION_1_4

Number Version constant for Java 1.4

public static final int
VERSION_1_5

Number Version constant for Java 1.5

public static final int
VERSION_1_6

Number Version constant for Java 1.6

public static final int
VERSION_1_7

Number Version constant for Java 1.7

public static final int
VERSION_1_8

Number Version constant for Java 1.8

public static final int
VERSION_1_9

Number Version constant for Java 1.9

public static final int
VERSION_9

Number Version constant for Java 9

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static String
addExtension(String command)

Adds a system specific extension to the name of an executable.

private static void
buildJrePackages()

demand creation of the package list.

public static File

Returns:

the file containing the command.
createVmsJavaOptionFile
(String[]
the command.
cmds
)

Writes the command into a temporary DCL script and returns the corresponding File object.

private static File

Returns:

null if the executable cannot be found.
findInDir
(String dirName, String commandName)

Look for an executable in a given directory.

public static String

Returns:

the java home value.
getJavaHome
()

Return the value of ${java.home}

public static String

Returns:

the version of Java as a String, e.g. "1.6" or "9"
getJavaVersion
()

Returns the version of Java this class is running under.

public static int

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.
getJavaVersionNumber
()

Deprecated use #getParsedJavaVersion instead
Returns the version of Java this class is running under.
public static String

Returns:

the path to the command.
getJdkExecutable
(String
the java executable to find.
command
)

Finds an executable that is part of a JDK installation based on the java.home system property.

public static String

Returns:

the path to the command.
getJreExecutable
(String
the java executable to find.
command
)

Finds an executable that is part of a JRE installation based on the java.home system property.

public static Vector<String>

Returns:

list of packages.
getJrePackages
()

get a vector of strings of packages built into that platforms runtime jar(s)

public static Vector<String>

Returns:

a list of test classes depending on the java version.
getJrePackageTestCases
()

Testing helper method; kept here for unification of changes.

public static DeweyDecimal

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.
getParsedJavaVersion
()

Returns the version of Java this class is running under.

public static boolean

Returns:

true if the current VM is Apache Harmony.
isApacheHarmony
()

Checks whether the current VM is Apache Harmony.

public static boolean

Returns:

true if the version of Java is the same or higher than the given version.
isAtLeastJavaVersion
(String
the version to check against the current version.
version
)

Compares the current Java version to the passed in String - assumes the argument is one of the constants defined in this class.

public static boolean

Returns:

true if the version of Java is GNU Classpath
isClasspathBased
()

Checks whether the current Java VM is GNU Classpath

public static boolean

Returns:

true if the current Java VM is gcj/gij.
isGij
()

Checks whether the current Java VM is the GNU interpreter gij or we are running in a gcj precompiled binary.

public static boolean

Returns:

true if the version of Java is the same as the given version.
isJavaVersion
(String
the version to check against the current version.
version
)

Compares the current Java version to the passed in String - assumes the argument is one of the constants defined in this class.

public static boolean

Returns:

true if the current Java VM is Kaffe.
isKaffe
()

Checks whether the current Java VM is Kaffe.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classpathDetectedback to summary
private static boolean classpathDetected

Whether this is a GNU Classpath based VM

FILE_UTILSback to summary
private static final FileUtils FILE_UTILS

FileUtils instance for path normalization

gijDetectedback to summary
private static boolean gijDetected

Whether this is the GNU VM (gcj/gij)

harmonyDetectedback to summary
private static boolean harmonyDetected

Whether this is Apache Harmony

IS_AIXback to summary
private static final boolean IS_AIX

Are we on AIX

IS_DOSback to summary
private static final boolean IS_DOS

Are we on a DOS-based system

IS_NETWAREback to summary
private static final boolean IS_NETWARE

Are we on Novell NetWare

JAVA_10back to summary
public static final String JAVA_10

Version constant for Java 10

Since
Ant 1.10.7
JAVA_11back to summary
public static final String JAVA_11

Version constant for Java 11

Since
Ant 1.10.7
JAVA_12back to summary
public static final String JAVA_12

Version constant for Java 12

Since
Ant 1.10.7
JAVA_1_0back to summary
public static final String JAVA_1_0

Version constant for Java 1.0

JAVA_1_1back to summary
public static final String JAVA_1_1

Version constant for Java 1.1

JAVA_1_2back to summary
public static final String JAVA_1_2

Version constant for Java 1.2

JAVA_1_3back to summary
public static final String JAVA_1_3

Version constant for Java 1.3

JAVA_1_4back to summary
public static final String JAVA_1_4

Version constant for Java 1.4

JAVA_1_5back to summary
public static final String JAVA_1_5

Version constant for Java 1.5

JAVA_1_6back to summary
public static final String JAVA_1_6

Version constant for Java 1.6

JAVA_1_7back to summary
public static final String JAVA_1_7

Version constant for Java 1.7

JAVA_1_8back to summary
public static final String JAVA_1_8

Version constant for Java 1.8

JAVA_1_9back to summary
public static final String JAVA_1_9

Deprecated

use #JAVA_9 instead

Version constant for Java 1.9

Annotations
@Deprecated
JAVA_9back to summary
public static final String JAVA_9

Version constant for Java 9

Since
Ant 1.9.8
JAVA_HOMEback to summary
private static final String JAVA_HOME

shortcut for System.getProperty("java.home")

javaVersionback to summary
private static String javaVersion

Version of currently running VM.

javaVersionNumberback to summary
private static int javaVersionNumber

floating version of the JVM

jrePackagesback to summary
private static Vector<String> jrePackages

array of packages in the runtime

kaffeDetectedback to summary
private static boolean kaffeDetected

Whether this is the Kaffe VM

parsedJavaVersionback to summary
private static final DeweyDecimal parsedJavaVersion

Version of currently running VM.

VERSION_10back to summary
public static final int VERSION_10

Number Version constant for Java 10

Since
Ant 1.10.7
VERSION_11back to summary
public static final int VERSION_11

Number Version constant for Java 11

Since
Ant 1.10.7
VERSION_12back to summary
public static final int VERSION_12

Number Version constant for Java 12

Since
Ant 1.10.7
VERSION_1_0back to summary
public static final int VERSION_1_0

Number Version constant for Java 1.0

VERSION_1_1back to summary
public static final int VERSION_1_1

Number Version constant for Java 1.1

VERSION_1_2back to summary
public static final int VERSION_1_2

Number Version constant for Java 1.2

VERSION_1_3back to summary
public static final int VERSION_1_3

Number Version constant for Java 1.3

VERSION_1_4back to summary
public static final int VERSION_1_4

Number Version constant for Java 1.4

VERSION_1_5back to summary
public static final int VERSION_1_5

Number Version constant for Java 1.5

VERSION_1_6back to summary
public static final int VERSION_1_6

Number Version constant for Java 1.6

VERSION_1_7back to summary
public static final int VERSION_1_7

Number Version constant for Java 1.7

VERSION_1_8back to summary
public static final int VERSION_1_8

Number Version constant for Java 1.8

VERSION_1_9back to summary
public static final int VERSION_1_9

Deprecated

use #VERSION_9 instead

Number Version constant for Java 1.9

Annotations
@Deprecated
VERSION_9back to summary
public static final int VERSION_9

Number Version constant for Java 9

Since
Ant 1.9.8

Constructor Detail

JavaEnvUtilsback to summary
private JavaEnvUtils()

Method Detail

addExtensionback to summary
private static String addExtension(String command)

Adds a system specific extension to the name of an executable.

Since
Ant 1.5
buildJrePackagesback to summary
private static void buildJrePackages()

demand creation of the package list. When you add a new package, add a new test below.

createVmsJavaOptionFileback to summary
public static File createVmsJavaOptionFile(String[] cmds) throws IOException

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:String[]

the command.

Returns:File

the file containing the command.

Exceptions
IOException:
if there is an error writing to the file.
findInDirback to summary
private static File findInDir(String dirName, String commandName)

Look for an executable in a given directory.

Returns:File

null if the executable cannot be found.

getJavaHomeback to summary
public static String getJavaHome()

Return the value of ${java.home}

Returns:String

the java home value.

getJavaVersionback to summary
public static String 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:String

the version of Java as a String, e.g. "1.6" or "9"

getJavaVersionNumberback to summary
public static int getJavaVersionNumber()

Deprecated

use #getParsedJavaVersion instead

Returns the version of Java this class is running under.

This number can be used for comparisons.

Returns:int

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.

Annotations
@Deprecated
getJdkExecutableback to summary
public static String getJdkExecutable(String command)

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 if JAVA_HOME points to your JDK installation.

Parameters
command:String

the java executable to find.

Returns:String

the path to the command.

Since
Ant 1.5
getJreExecutableback to summary
public static String getJreExecutable(String command)

Finds an executable that is part of a JRE installation based on the java.home system property.

java, keytool, policytool, orbd, rmid, rmiregistry, servertool and tnameserv are JRE executables on Sun based JRE's.

You typically find them in JAVA_HOME/jre/bin if JAVA_HOME points to your JDK installation. JDK < 1.2 has them in the same directory as the JDK executables.

Parameters
command:String

the java executable to find.

Returns:String

the path to the command.

Since
Ant 1.5
getJrePackagesback to summary
public static Vector<String> getJrePackages()

get a vector of strings of packages built into that platforms runtime jar(s)

Returns:Vector<String>

list of packages.

getJrePackageTestCasesback to summary
public static Vector<String> getJrePackageTestCases()

Testing helper method; kept here for unification of changes.

Returns:Vector<String>

a list of test classes depending on the java version.

getParsedJavaVersionback to summary
public static DeweyDecimal getParsedJavaVersion()

Returns the version of Java this class is running under.

This number can be used for comparisons.

Returns:DeweyDecimal

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.

isApacheHarmonyback to summary
public static boolean isApacheHarmony()

Checks whether the current VM is Apache Harmony.

Returns:boolean

true if the current VM is Apache Harmony.

Since
Ant 1.8.2
isAtLeastJavaVersionback to summary
public 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. Note that Ant now requires JDK 1.8+ so JAVA_1_0 through JAVA_1_7 need no longer be tested for.

Parameters
version:String

the version to check against the current version.

Returns:boolean

true if the version of Java is the same or higher than the given version.

Since
Ant 1.7
isClasspathBasedback to summary
public static boolean isClasspathBased()

Checks whether the current Java VM is GNU Classpath

Returns:boolean

true if the version of Java is GNU Classpath

Since
Ant 1.9.1
isGijback to summary
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:boolean

true if the current Java VM is gcj/gij.

Since
Ant 1.8.2
isJavaVersionback to summary
public 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. Note that Ant now requires JDK 1.8+ so JAVA_1_0 through JAVA_1_7 need no longer be tested for.

Parameters
version:String

the version to check against the current version.

Returns:boolean

true if the version of Java is the same as the given version.

Since
Ant 1.5
isKaffeback to summary
public static boolean isKaffe()

Checks whether the current Java VM is Kaffe.

Returns:boolean

true if the current Java VM is Kaffe.

Since
Ant 1.6.3
See Also
https://github.com/kaffe/kaffe