Supports JRE versioning schema for 8 and earlier (ex: 1.8.0_252) as well as 9+ (ex: 11.0.2)
| Constructor and description |
|---|
JreVersion
(java.lang.String versionString)Construct Java Runtime Environment (JRE) and/or Java Development Kit (JDK) version from the given version string. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
boolean |
equals(java.lang.Object o) |
|
int |
getJavaRuntimeVersion()Helper method to get the main Java version number since this value is contained in a different location in the version string for Java 8- and Java 9+ |
|
int |
getMajor()@return The major component as an integer |
|
java.lang.String |
getMajorMinor()Get the major and minor components of the version. |
|
int |
getMinor()@return The minor component as an integer |
|
int |
getPatch()@return The patch component as an integer |
|
int |
getUpdateVersion()@return the update version as an integer, note that this is only applicable to Java 8 and older and will be 0 for 9+ |
|
int |
hashCode() |
|
boolean |
isJava8OrOlder()Helper method to check if the version being captured is Java 8 or older since that uses one naming scheme (MAJ.MIN.PATCH_UPDATE). |
|
java.lang.String |
toString()@return The full version including the stage, e.g., '11.0.2' or '1.8.0_252' |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Construct Java Runtime Environment (JRE) and/or Java Development Kit (JDK) version from the given version string. The string must start with the format: 'MAJ.MIN.PATCH' with support for version-specific formats (up to, and including, Java 8, which used the 'MAJ.MIN.PATCH_UPDATE' format, as well as the Java 9+ format which uses the 'MAJ.MIN.PATCH', but no update).
If MAJ, MIN, PATCH, and (if applicable) UPDATE) are not each convertible to an integer, then an exception will be thrown. Similarly, if the version number is invalid due to insufficient information or too much information, an exception will be thrown. There is no specific validation against existing JRE release versions.
This can handle JDK8- as well as JDK9+ version number schema. Specifically, JDK8- (that is, 8 and earlier) are versioned like "MAJ.MIN.PATCH_UPDATE" where MAJ is always 1, and MIN is the JDK release (ex: 8 for JDK8). Providing more or less than 4 values will result in an exception. JDK 9+ uses a different format, specifically MAJ.MIN.PATCH. There is no update version. Providing more or less than 3 values will result in an exception.
The <= JDK8 versions are parsed with some leniency, specifically the use of an underscore to denote the update version is standard, but any non-numeric character will work (including "." and "u"). However, the non-standard separator will not be preserved, the full version string is normalized to the underscore format.
versionString - The string to parse, e.g., '11.0.2' or '1.8.0_252'Helper method to get the main Java version number since this value is contained in a different location in the version string for Java 8- and Java 9+
Get the major and minor components of the version. For example, if the full version is 1.8.0_252, then this method returns '1.8'.
Helper method to check if the version being captured is Java 8 or older since that uses one naming scheme (MAJ.MIN.PATCH_UPDATE). Otherwise, it is assumed to be Java 9 or newer which uses the MAJ.MIN.PATCH format. There is some rudimentary validation by checking the minor version is greater than 0, or less than/equal to 8 and the major version is always 1.