Class JavaEnvUtils

java.lang.Object
org.apache.tools.ant.util.JavaEnvUtils

public final class JavaEnvUtils extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Version constant for Java 1.0
    static final String
    Version constant for Java 1.1
    static final String
    Version constant for Java 1.2
    static final String
    Version constant for Java 1.3
    static final String
    Version constant for Java 1.4
    static final String
    Version constant for Java 1.5
    static final String
    Version constant for Java 1.6
    static final String
    Version constant for Java 1.7
    static final String
    Version constant for Java 1.8
    static final String
    Deprecated.
    use #JAVA_9 instead
    static final String
    Version constant for Java 10
    static final String
    Version constant for Java 11
    static final String
    Version constant for Java 12
    static final String
    Version constant for Java 9
    static final int
    Number Version constant for Java 1.0
    static final int
    Number Version constant for Java 1.1
    static final int
    Number Version constant for Java 1.2
    static final int
    Number Version constant for Java 1.3
    static final int
    Number Version constant for Java 1.4
    static final int
    Number Version constant for Java 1.5
    static final int
    Number Version constant for Java 1.6
    static final int
    Number Version constant for Java 1.7
    static final int
    Number Version constant for Java 1.8
    static final int
    Deprecated.
    use #VERSION_9 instead
    static final int
    Number Version constant for Java 10
    static final int
    Number Version constant for Java 11
    static final int
    Number Version constant for Java 12
    static final int
    Number Version constant for Java 9
  • Method Summary

    Modifier and Type
    Method
    Description
    static File
    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 instead
    static String
    Finds an executable that is part of a JDK installation based on the java.home system property.
    static String
    Finds an executable that is part of a JRE installation based on the java.home system property.
    static Vector<String>
    get a vector of strings of packages built into that platforms runtime jar(s)
    static Vector<String>
    Testing helper method; kept here for unification of changes.
    Returns the version of Java this class is running under.
    static boolean
    Checks whether the current VM is Apache Harmony.
    static boolean
    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 Classpath
    static boolean
    Checks whether the current Java VM is the GNU interpreter gij or we are running in a gcj precompiled binary.
    static boolean
    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 Kaffe.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • getJavaVersion

      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:
      the version of Java as a String, e.g. "1.6" or "9"
    • getJavaVersionNumber

      @Deprecated 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:
      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

      public static DeweyDecimal 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

      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 - 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

      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 - 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

      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 - the java executable to find.
      Returns:
      the path to the command.
      Since:
      Ant 1.5
    • getJdkExecutable

      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 - the java executable to find.
      Returns:
      the path to the command.
      Since:
      Ant 1.5
    • getJrePackageTestCases

      public static Vector<String> getJrePackageTestCases()
      Testing helper method; kept here for unification of changes.
      Returns:
      a list of test classes depending on the java version.
    • getJrePackages

      public static Vector<String> getJrePackages()
      get a vector of strings of packages built into that platforms runtime jar(s)
      Returns:
      list of packages.
    • createVmsJavaOptionFile

      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 - the command.
      Returns:
      the file containing the command.
      Throws:
      IOException - if there is an error writing to the file.
    • getJavaHome

      public static String getJavaHome()
      Return the value of ${java.home}
      Returns:
      the java home value.