classSource
public final class JavaManager

Resolves, 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

public static JavaInstallation currentRuntime()
Resolves the current JVM as a Java installation.
Returns
JavaInstallationThe current runtime information
public static JavaInstallation ensureExactJavaVersion(int requiredMajorVersion) throws HttpException, IOException
Ensures 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
requiredMajorVersionintThe required Java feature version
Returns
JavaInstallationThe current JVM if it has exactly the required feature version, otherwise a managed Java installation
Throws
HttpExceptionIf the runtime manifest request fails
IOExceptionIf a runtime download or extraction fails
public static Path ensureJavaExecutable(String minecraftVersion) throws HttpException, IOException
Resolves the Java executable for a Minecraft version, downloading a compatible runtime if the current JVM is too old.
Parameters
minecraftVersionStringThe Minecraft version id
Returns
PathThe Java executable to use for launching Minecraft
Throws
HttpExceptionIf a manifest request fails
IOExceptionIf a runtime download or extraction fails
public static Path ensureJavaExecutable(int requiredMajorVersion) throws HttpException, IOException
Resolves the Java executable for a feature version.
Parameters
requiredMajorVersionintThe required Java feature version
Returns
PathThe Java executable to use for launching Minecraft
Throws
HttpExceptionIf a runtime manifest request fails
IOExceptionIf a runtime download or extraction fails
public static JavaInstallation ensureJavaForMinecraftVersion(String minecraftVersion) throws HttpException, IOException
Ensures that a suitable Java runtime is available for a Minecraft version.
Parameters
minecraftVersionStringThe Minecraft version id, such as 1.21.4
Returns
JavaInstallationThe current JVM if it matches the required feature version, otherwise a managed Java installation
Throws
HttpExceptionIf a manifest request fails
IOExceptionIf a runtime download or extraction fails
public static JavaInstallation ensureJavaVersion(int requiredMajorVersion) throws HttpException, IOException
Ensures that a suitable Java runtime is available for the given feature version.
Parameters
requiredMajorVersionintThe required Java feature version
Returns
JavaInstallationThe current JVM if it matches the required feature version, otherwise a managed Java installation
Throws
HttpExceptionIf the runtime manifest request fails
IOExceptionIf a runtime download or extraction fails
public static Path getBaseDir()
Returns
PathThe 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
versionJsonJsonValueA parsed Minecraft version JSON
Returns
intThe 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
versionJsonJsonFileA parsed Minecraft version JSON file
Returns
intThe required Java major version, or -1 if the document does not contain one
public static int getRequiredJavaVersion(String minecraftVersion) throws HttpException, IOException
Resolves the required Java version for the given Minecraft version id.
Parameters
minecraftVersionStringThe Minecraft version id, such as 1.21.4
Returns
intThe required Java major version, or -1 if it could not be resolved
Throws
HttpExceptionIf a manifest request fails
IOExceptionIf the version JSON cannot be read
public static int getRequiredJavaVersion(Path versionJsonPath) throws IOException
Resolves the required Java version for the given Minecraft version id from a local cache file.
Parameters
versionJsonPathPathThe cached Minecraft version JSON path
Returns
intThe required Java major version, or -1 if it could not be resolved
Throws
IOExceptionIf the file cannot be read
public static String getVersionJsonUrl(String minecraftVersion) throws HttpException, IOException
Resolves the version JSON URL for a Minecraft version id.
Parameters
minecraftVersionStringThe Minecraft version id
Returns
StringThe Mojang metadata URL, or null if the version was not found
Throws
HttpExceptionIf the version manifest request fails
IOExceptionIf the manifest cannot be read
public static void init(Path baseDir, EventBus eventBus)
Configures the root directory used for managed Java runtimes.
Parameters
baseDirPathThe directory where managed runtimes will be stored
eventBusEventBusThe EventBus Events will be pushed to
public static void init(Path baseDir)
Parameters
baseDirPath