Package com.dianxin.tori.base.utils
Class VersionManager
java.lang.Object
com.dianxin.tori.base.utils.VersionManager
Utility class for querying and validating the Java runtime version.
This class provides helper methods to detect the Java version currently running the application and to verify compatibility against a required minimum Java version.
It is primarily intended to be used during application startup or bootstrap phases to ensure the runtime environment meets the minimum requirements of the framework.
Example usage
int current = VersionManager.getJavaVersionRunning();
if (!VersionManager.isCompatibleJavaVersion(21)) {
throw new UnsupportedOperationException(
"Java 21 or newer is required"
);
}
This class is a pure utility class and must not be instantiated.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic intReturns the major feature version of the Java runtime currently running the application.static StringReturns the full Java runtime version string.static booleanisCompatibleJavaVersion(int requiredVersion) Checks whether the currently running Java version is compatible with the specified minimum required version.static booleanisJavaVersionInRange(int min, int max) Checks whether the current Java version falls within the given range.static booleanChecks whether the current Java version is a Long-Term Support (LTS) release.static voidrequireJavaVersion(int requiredVersion) Ensures that the current Java version meets the required minimum version.static voidrequireJavaVersion(int requiredVersion, boolean shutdown) Ensures that the current Java version meets the required minimum version.
-
Field Details
-
DIANXIN_API_VERSION
- See Also:
-
-
Method Details
-
getJavaVersionRunning
public static int getJavaVersionRunning()Returns the major feature version of the Java runtime currently running the application.For example:
- Java 8 → returns
8 - Java 11 → returns
11 - Java 17 → returns
17 - Java 21 → returns
21
- Returns:
- the major Java version (feature version)
- Java 8 → returns
-
getJavaVersionString
Returns the full Java runtime version string.- Returns:
- the Java runtime version (e.g. "21.0.2")
-
isCompatibleJavaVersion
public static boolean isCompatibleJavaVersion(int requiredVersion) Checks whether the currently running Java version is compatible with the specified minimum required version.A version is considered compatible if:
currentVersion >= requiredVersion- Parameters:
requiredVersion- the minimum required Java version- Returns:
trueif the current Java version is equal to or greater than the required version,falseotherwise
-
requireJavaVersion
public static void requireJavaVersion(int requiredVersion) Ensures that the current Java version meets the required minimum version.- Parameters:
requiredVersion- the minimum required Java version- Throws:
UnsupportedOperationException- if the Java version is incompatible
-
requireJavaVersion
public static void requireJavaVersion(int requiredVersion, boolean shutdown) Ensures that the current Java version meets the required minimum version.- Parameters:
requiredVersion- the minimum required Java version- Throws:
UnsupportedOperationException- if the Java version is incompatible
-
isJavaVersionInRange
public static boolean isJavaVersionInRange(int min, int max) Checks whether the current Java version falls within the given range.- Parameters:
min- minimum Java version (inclusive)max- maximum Java version (inclusive)- Returns:
- true if current version is within range
-
isLtsVersion
public static boolean isLtsVersion()Checks whether the current Java version is a Long-Term Support (LTS) release.- Returns:
- true if the Java version is LTS
-