Package org.projectnessie.quarkus.runner
Class JavaVM
- java.lang.Object
-
- org.projectnessie.quarkus.runner.JavaVM
-
public final class JavaVM extends Object
Helper class to locate a JDK by Java major version and return the path to thejavaexecutable.
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_JAVA_VERSION_TO_CHECK
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intcurrentJavaVMMajorVersion()static JavaVMfindJavaVM(int majorVersion)static JavaVMfindJavaVMTryExact(int majorVersion)Find a Java-Home that exactly matches the given Java major version.static JavaVMforJavaHome(String javaHome)static JavaVMforJavaHome(Path javaHome)static JavaVMgetCurrentJavaVM()Get theJavaVMinstance for the current JVM.PathgetJavaExecutable()PathgetJavaHome()static intmajorVersionFromString(String versionString)Extracts the major version from a Java-version-string as returned fromSystem.getProeprty("java.version).
-
-
-
Field Detail
-
MAX_JAVA_VERSION_TO_CHECK
public static final int MAX_JAVA_VERSION_TO_CHECK
- See Also:
- Constant Field Values
-
-
Method Detail
-
findJavaVM
public static JavaVM findJavaVM(int majorVersion)
Loops frommajorVersionup to 19 until a call tofindJavaVMTryExact(int)returns a Java-Home.Returns the current JVM from
getCurrentJavaVM(), if its major version is greater than or equal to the requestedmajorVersion.- Parameters:
majorVersion- the Java major-version to start with.- Returns:
- a Java-VM on the local system or
null, if no matching Java-Home could be found.
-
findJavaVMTryExact
public static JavaVM findJavaVMTryExact(int majorVersion)
Find a Java-Home that exactly matches the given Java major version.Searches for the Java-Home in these places in this exact order:
- Environment variable
JDKxx_HOME, wherexxis themajorVersion. - Environment variable
JAVAxx_HOME, wherexxis themajorVersion. - System property
jdkXX.home, whereXXis themajorVersion. - System property
javaXX.home, whereXXis themajorVersion. - Using the
/usr/libexec/java_homeon MacOS, which may return a newer Java version.
- Parameters:
majorVersion- the Java major-version to search for.- Returns:
- a Java-VM on the local system or
null, if no matching Java-Home could be found.
- Environment variable
-
getCurrentJavaVM
public static JavaVM getCurrentJavaVM()
Get theJavaVMinstance for the current JVM.- Returns:
JavaVMinstance for the current JVM, nevernull.
-
currentJavaVMMajorVersion
public static int currentJavaVMMajorVersion()
-
majorVersionFromString
public static int majorVersionFromString(String versionString)
Extracts the major version from a Java-version-string as returned fromSystem.getProeprty("java.version).- Parameters:
versionString- the Java-version-string- Returns:
- extracted Java major version
-
getJavaHome
public Path getJavaHome()
-
getJavaExecutable
public Path getJavaExecutable()
-
-