minified-java/com.dervarex.minified.java
JavaManager
classSource
public final class JavaManagerResolves, downloads, and caches Java runtimes for Minecraft launches.
This manager can inspect Minecraft version metadata, determine the required Java feature version, and download a matching runtime when the current JVM is too old.
The default runtime cache is placed under a user-specific application directory, but callers
may override it with init(Path).
Methods
JavaInstallation currentRuntime()Resolves the current JVM as a Java installation.JavaInstallation ensureExactJavaVersion(int)Ensures that a Java runtime of exactly the given feature version is available.Path ensureJavaExecutable(String)Resolves the Java executable for a Minecraft version, downloading a compatible runtime if
the current JVM is too old.Path ensureJavaExecutable(int)Resolves the Java executable for a feature version.JavaInstallation ensureJavaForMinecraftVersion(String)Ensures that a suitable Java runtime is available for a Minecraft version.JavaInstallation ensureJavaVersion(int)Ensures that a suitable Java runtime is available for the given feature version.Path getBaseDir()int getRequiredJavaVersion(JsonValue)Reads the required Java major version from a Minecraft version JSON document.int getRequiredJavaVersion(JsonFile)Reads the required Java major version from a Minecraft version JSON document.int getRequiredJavaVersion(String)Resolves the required Java version for the given Minecraft version id.int getRequiredJavaVersion(Path)Resolves the required Java version for the given Minecraft version id from a local cache file.String getVersionJsonUrl(String)Resolves the version JSON URL for a Minecraft version id.void init(Path, EventBus)Configures the root directory used for managed Java runtimes.void init(Path)currentRuntime()
staticSource
public static JavaInstallation currentRuntime()Resolves the current JVM as a Java installation.
| Returns | ||
|---|---|---|
JavaInstallation | The current runtime information | |
public static JavaInstallation ensureExactJavaVersion(int requiredMajorVersion) throws HttpException, IOExceptionEnsures that a Java runtime of exactly the given feature version is available.
Unlike
ensureJavaVersion(int), a newer current JVM is not accepted,
which is needed for Minecraft mod loaders relying on the Java 8 class loader
May download and extract a runtime (network and disk I/O)| Parameters | ||
|---|---|---|
requiredMajorVersion | int | The required Java feature version |
| Returns | ||
JavaInstallation | The current JVM if it has exactly the required feature version, otherwise a managed Java installation | |
| Throws | ||
HttpException | If the runtime manifest request fails | |
IOException | If a runtime download or extraction fails | |
public static Path ensureJavaExecutable(String minecraftVersion) throws HttpException, IOExceptionResolves the Java executable for a Minecraft version, downloading a compatible runtime if
the current JVM is too old.
| Parameters | ||
|---|---|---|
minecraftVersion | String | The Minecraft version id |
| Returns | ||
Path | The Java executable to use for launching Minecraft | |
| Throws | ||
HttpException | If a manifest request fails | |
IOException | If a runtime download or extraction fails | |
public static Path ensureJavaExecutable(int requiredMajorVersion) throws HttpException, IOExceptionResolves the Java executable for a feature version.
| Parameters | ||
|---|---|---|
requiredMajorVersion | int | The required Java feature version |
| Returns | ||
Path | The Java executable to use for launching Minecraft | |
| Throws | ||
HttpException | If a runtime manifest request fails | |
IOException | If a runtime download or extraction fails | |
public static JavaInstallation ensureJavaForMinecraftVersion(String minecraftVersion) throws HttpException, IOExceptionEnsures that a suitable Java runtime is available for a Minecraft version.
| Parameters | ||
|---|---|---|
minecraftVersion | String | The Minecraft version id, such as 1.21.4 |
| Returns | ||
JavaInstallation | The current JVM if it matches the required feature version, otherwise a managed Java installation | |
| Throws | ||
HttpException | If a manifest request fails | |
IOException | If a runtime download or extraction fails | |
public static JavaInstallation ensureJavaVersion(int requiredMajorVersion) throws HttpException, IOExceptionEnsures that a suitable Java runtime is available for the given feature version.
| Parameters | ||
|---|---|---|
requiredMajorVersion | int | The required Java feature version |
| Returns | ||
JavaInstallation | The current JVM if it matches the required feature version, otherwise a managed Java installation | |
| Throws | ||
HttpException | If the runtime manifest request fails | |
IOException | If a runtime download or extraction fails | |
getBaseDir()
staticSource
public static Path getBaseDir()| Returns | ||
|---|---|---|
Path | The configured root directory used for managed Java runtimes | |
public static int getRequiredJavaVersion(JsonValue versionJson)Reads the required Java major version from a Minecraft version JSON document.
| Parameters | ||
|---|---|---|
versionJson | JsonValue | A parsed Minecraft version JSON |
| Returns | ||
int | The required Java major version, or -1 if the document does not contain one | |
public static int getRequiredJavaVersion(JsonFile versionJson)Reads the required Java major version from a Minecraft version JSON document.
| Parameters | ||
|---|---|---|
versionJson | JsonFile | A parsed Minecraft version JSON file |
| Returns | ||
int | The required Java major version, or -1 if the document does not contain one | |
public static int getRequiredJavaVersion(String minecraftVersion) throws HttpException, IOExceptionResolves the required Java version for the given Minecraft version id.
| Parameters | ||
|---|---|---|
minecraftVersion | String | The Minecraft version id, such as 1.21.4 |
| Returns | ||
int | The required Java major version, or -1 if it could not be resolved | |
| Throws | ||
HttpException | If a manifest request fails | |
IOException | If the version JSON cannot be read | |
public static int getRequiredJavaVersion(Path versionJsonPath) throws IOExceptionResolves the required Java version for the given Minecraft version id from a local cache file.
| Parameters | ||
|---|---|---|
versionJsonPath | Path | The cached Minecraft version JSON path |
| Returns | ||
int | The required Java major version, or -1 if it could not be resolved | |
| Throws | ||
IOException | If the file cannot be read | |
public static String getVersionJsonUrl(String minecraftVersion) throws HttpException, IOExceptionResolves the version JSON URL for a Minecraft version id.
| Parameters | ||
|---|---|---|
minecraftVersion | String | The Minecraft version id |
| Returns | ||
String | The Mojang metadata URL, or null if the version was not found | |
| Throws | ||
HttpException | If the version manifest request fails | |
IOException | If the manifest cannot be read | |
public static void init(Path baseDir, EventBus eventBus)init(Path)
staticSource
public static void init(Path baseDir)| Parameters | ||
|---|---|---|
baseDir | Path | |