org.schmant.support
Class JdkUtil

java.lang.Object
  extended by org.schmant.support.JdkUtil

public final class JdkUtil
extends Object

This is a support class for working with JDK installations.

Since:
0.5
Author:
Karl Gustafsson

Method Summary
static JdkVersion getCurrentJdkVersion()
          Get the version of the currently running JVM.
static File getJdkExecutable(File javaHome, String cmd, String... extensions)
          Get a JDK command such as java or javac from a Java installation.
static File getJdkExecutable(String cmd, String... extensions)
          Get a JDK command such as java or javac from the default Java installation.
static File getJdkExecutableOrNull(File javaHome, String cmd, String... extensions)
          Get a JDK command such as java or javac from the bin catalog of a Java installation.
static File getJdkFile(File javaHome, String relPath)
          Get a Java installation file, such as jre/lib/rt.jar.
static File getJdkFile(String relPath)
          Get a Java installation file.
static File getJdkFileOrNull(File javaHome, String relPath)
          Get a file, if it can be found, from a Java installation.
static File getJdkFileOrNull(String relPath)
          Get a file from the default Java installation.
static JdkVersion getJdkVersion()
          Get the version of the default Java installation.
static JdkVersion getJdkVersion(File javaHome)
          Get the version of the Java version with its home directory in javaHome.
static JdkVersion getJdkVersionFromJavaExecutable(File javaExecutable)
          Get the version of the supplied Java executable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getJdkExecutableOrNull

public static File getJdkExecutableOrNull(File javaHome,
                                          String cmd,
                                          String... extensions)
Get a JDK command such as java or javac from the bin catalog of a Java installation. First, javaHome is searched, then the PATH environment variable is searched.

Tip: The org.entityfs.support.io.OsPlatform class can be used to check if the program is running on Windows or not.

Parameters:
javaHome - The Java home directory. If this is set to null, the JAVA_HOME environment variable is used. If that is not set, the system property java.home (pointing to the installation of the currently running JVM) is used instead.
cmd - The name of the command, e.g. javac-
extensions - The list of file name extensions (no leading dot) that the file might have, for instance "", "exe".
Returns:
The absolute path to the command, if found, or null if the command was not found.

getJdkExecutable

public static File getJdkExecutable(File javaHome,
                                    String cmd,
                                    String... extensions)
                             throws EntityNotFoundException
Get a JDK command such as java or javac from a Java installation. First, javaHome is searched, then the PATH environment variable is searched.

Tip: The org.entityfs.support.io.OsPlatform class can be used to check if the program is running on Windows or not.

Parameters:
javaHome - The Java home directory. If this is set to null, the JAVA_HOME environment variable is used. If that is not set, the system property java.home (pointing to the installation of the currently running JVM) is used instead.
cmd - The name of the command, e.g. javac-
extensions - The list of file name extensions (lo leading dot) that the file might have, for instance "", "exe".
Returns:
The absolute path to the command.
Throws:
EntityNotFoundException - If the command was not found.

getJdkExecutable

public static File getJdkExecutable(String cmd,
                                    String... extensions)
                             throws EntityNotFoundException
Get a JDK command such as java or javac from the default Java installation. First, the directory under the JAVA_HOME environment variable is searched, if it is set, then the PATH environment variable is searched.

Tip: The org.entityfs.support.io.OsPlatform class can be used to check if the program is running on Windows or not.

Parameters:
cmd - The name of the command, e.g. javac-
extensions - The list of file name extensions (lo leading dot) that the file might have, for instance "", "exe".
Returns:
The absolute path to the command.
Throws:
EntityNotFoundException - If the command was not found.

getJdkFileOrNull

public static File getJdkFileOrNull(File javaHome,
                                    String relPath)
Get a file, if it can be found, from a Java installation. If the file is not found in the javaHome, the PATH environment variable is searched for a java command, and, if found, that Java installation is searched for the file.

Parameters:
javaHome - The Java home directory. If this is set to null, the JAVA_HOME environment variable is used. If that is not set, the system property java.home (pointing to the installation of the currently running JVM) is used instead.
relPath - The path of the file, relative to the Java installation.
Returns:
The file, or null if the file is not found.

getJdkFileOrNull

public static File getJdkFileOrNull(String relPath)
Get a file from the default Java installation. If the JAVA_HOME environment variable is set, that is used to find a Java installation. Otherwise the java.home (pointing to the path of the currently running JVM) is used.

See getJdkFileOrNull(File, String) for more details.

Parameters:
relPath - The path of the file relative to the Java installation.
Returns:
The file, or null if it was not found.

getJdkFile

public static File getJdkFile(File javaHome,
                              String relPath)
                       throws EntityNotFoundException
Get a Java installation file, such as jre/lib/rt.jar. See getJdkFileOrNull(File, String)

Parameters:
javaHome - The Java home directory. If this is set to null, the JAVA_HOME environment variable is used. If that is not set, the system property java.home (pointing to the installation of the currently running JVM) is used instead.
relPath - The path of the file relative to the Java installation.
Returns:
The file
Throws:
EntityNotFoundException - If the file is not found

getJdkFile

public static File getJdkFile(String relPath)
                       throws EntityNotFoundException
Get a Java installation file. See getJdkFileOrNull(File, String) .

Parameters:
relPath - The path of the file relative to the Java installation
Returns:
The file.
Throws:
EntityNotFoundException - If the file is not found

getJdkVersion

public static JdkVersion getJdkVersion(File javaHome)
                                throws InterruptedException
Get the version of the Java version with its home directory in javaHome.

Parameters:
javaHome - The home directory of the Java installation.
Returns:
The version of the Java installation under javaHome.
Throws:
InterruptedException
See Also:
getJdkVersion(), getJdkVersionFromJavaExecutable(File)

getJdkVersion

public static JdkVersion getJdkVersion()
                                throws InterruptedException
Get the version of the default Java installation. If the JAVA_HOME environment variable is set, that is used to find a Java installation. Otherwise the java.home (pointing to the path of the currently running JVM) is used.

Returns:
The version of the default Java installation.
Throws:
InterruptedException
See Also:
getJdkVersion(File), getJdkVersionFromJavaExecutable(File)

getJdkVersionFromJavaExecutable

public static JdkVersion getJdkVersionFromJavaExecutable(File javaExecutable)
                                                  throws InterruptedException
Get the version of the supplied Java executable.

Parameters:
javaExecutable - A Java executable such as java.exe on Windows.
Returns:
The version of the Java executable.
Throws:
InterruptedException
See Also:
getJdkVersion(File), getJdkVersion()

getCurrentJdkVersion

public static JdkVersion getCurrentJdkVersion()
Get the version of the currently running JVM.

Returns:
The version of the currently running JVM.