Package adams.core.management
Class Java
- java.lang.Object
-
- adams.core.management.Java
-
-
Field Summary
Fields Modifier and Type Field Description static StringBIN_DIRthe sub-directory with the binaries.protected static StringCLASSPATH_FULLthe cleaned up, full classpath.protected static StringCLASSPATH_SHORTthe shortened classpath.static StringJAVAthe java executable (no extension).static StringJAVACthe javac executable (no extension).protected static IntegerMAJOR_VERSIONthe major Java version.
-
Constructor Summary
Constructors Constructor Description Java()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancanStopThread()Returns whether we can call Thread.stop().protected static Stringexecute(String executable, String options)Executes the executable and returns the output.static StringgetBinDir()Returns the "bin" directory of the Java home.static StringgetBinDir(String path)Returns the "bin" directory.static StringgetClassPath(boolean shorten)Returns the classpath of the current JVM.static StringgetHome()Returns the Java home directory of the current JVM.static StringgetJavaExecutable()Returns the java executable.static intgetMajorVersion()Returns the major version of Java.static booleanisJDK()Checks whether Java home is representing a JDK.static booleanisJDK(String path)Checks whether directory is representing a JDK.static booleanisJRE()Checks whether Java home is pointing to a JRE instead of a JDK.static booleanisJRE(String path)Checks whether directory is pointing to a JRE instead of a JDK.static voidmain(String[] args)For testing only.
-
-
-
Field Detail
-
BIN_DIR
public static final String BIN_DIR
the sub-directory with the binaries.- See Also:
- Constant Field Values
-
JAVA
public static final String JAVA
the java executable (no extension).- See Also:
- Constant Field Values
-
JAVAC
public static final String JAVAC
the javac executable (no extension).- See Also:
- Constant Field Values
-
CLASSPATH_FULL
protected static String CLASSPATH_FULL
the cleaned up, full classpath.
-
CLASSPATH_SHORT
protected static String CLASSPATH_SHORT
the shortened classpath.
-
MAJOR_VERSION
protected static Integer MAJOR_VERSION
the major Java version.
-
-
Method Detail
-
getMajorVersion
public static int getMajorVersion()
Returns the major version of Java.- Returns:
- the major version, -1 if failed to determine
-
getHome
public static String getHome()
Returns the Java home directory of the current JVM.- Returns:
- the home directory
-
isJRE
public static boolean isJRE()
Checks whether Java home is pointing to a JRE instead of a JDK. It is checking for the javac executable.- Returns:
- true if the JVM is just a JRE
- See Also:
isJRE(String)
-
isJRE
public static boolean isJRE(String path)
Checks whether directory is pointing to a JRE instead of a JDK. It is checking for the javac executable.- Parameters:
path- the path above the "bin" directory- Returns:
- true if the JVM is just a JRE
- See Also:
JAVAC
-
isJDK
public static boolean isJDK()
Checks whether Java home is representing a JDK. If the directory is JRE, it is checked whether it is just the JRE of a JDK.- Returns:
- true if the JVM is a JDK
- See Also:
isJDK(String)
-
isJDK
public static boolean isJDK(String path)
Checks whether directory is representing a JDK. If the directory is JRE, it is checked whether it is just the JRE of a JDK.- Parameters:
path- the path above the "bin" directory- Returns:
- true if the JVM is a JDK
- See Also:
JAVAC
-
getBinDir
public static String getBinDir()
Returns the "bin" directory of the Java home. In case of a JRE of a JDK, this returns the JDK/bin directory and not the JRE/bin one.- Returns:
- the absolute path to "bin" (incl.)
- See Also:
getBinDir(String)
-
getBinDir
public static String getBinDir(String path)
Returns the "bin" directory. In case of a JRE of a JDK, this returns the JDK/bin directory and not the JRE/bin one.- Parameters:
path- above the "bin"- Returns:
- the absolute path to "bin" (incl.)
- See Also:
BIN_DIR
-
getJavaExecutable
public static String getJavaExecutable()
Returns the java executable.- Returns:
- the full path to the java executable
- See Also:
JAVA,getBinDir()
-
execute
protected static String execute(String executable, String options)
Executes the executable and returns the output.- Parameters:
executable- the jvisualvm executable to useoptions- additional options for jvisualvm- Returns:
- the output
-
getClassPath
public static String getClassPath(boolean shorten)
Returns the classpath of the current JVM. Does not check whether the directories or jars actually exist, but removes "fake" jars that occur on Mac OSX when unzipping a ZIP file containing jars (these files start with "._").- Parameters:
shorten- if true then the paths get removed from the jars- Returns:
- the classpath
-
canStopThread
public static boolean canStopThread()
Returns whether we can call Thread.stop().- Returns:
- true if possible
-
main
public static void main(String[] args)
For testing only.- Parameters:
args- each argument is interpreted as a directory to test for JRE/JDK/etc.
-
-