Fix 12: Add forge client jar to classpath (missing from version JSON libs)

The forge patched client jar (forge-<version>-client.jar) contains all
Minecraft classes with Automatic-Module-Name: minecraft, but it is NOT
listed in the version JSON libraries array - so buildClasspathFromManifest
does not include it on the -cp. FML discovers it by scanning the library
directory, but securejarhandler only processes classpath entries to create
named modules.

This fix explicitly finds and prepends forge-<version>-client.jar to the
classpath when launching Forge/NeoForge, so securejarhandler can create
the minecraft module from it.
This commit is contained in:
SashegDev
2026-07-13 16:33:26 +00:00
parent 0a388c90fd
commit f58db7f941
@@ -63,12 +63,7 @@ public class LaunchCommandBuilder {
// always use ModLauncher as main class (version.json might have
// BootstrapLauncher which breaks with Java module system)
if ("forge".equals(loaderType) || "neoforge".equals(loaderType)) {
// Build classpath from manifest libraries only.
// The forge client jar (forge-*-client.jar) on the classpath
// contains the patched Minecraft classes and has
// Automatic-Module-Name: minecraft in its MANIFEST.
// We modify the ignoreList below to NOT exclude it,
// so securejarhandler creates the "minecraft" module from it.
// Build classpath from manifest libraries.
String classpath;
if (manifest != null) {
classpath = buildClasspathFromManifest(manifest, false);
@@ -79,6 +74,25 @@ public class LaunchCommandBuilder {
classpath = buildVanillaClasspath();
}
// The forge client jar (forge-*-client.jar) is NOT listed in the
// version JSON's libraries array, so it's NOT on the classpath.
// FML discovers it by scanning the library directory, but
// securejarhandler only processes classpath entries.
// We add it explicitly so securejarhandler creates the "minecraft"
// module from its Automatic-Module-Name: minecraft.
String forgeVersion = instance.getMinecraftVersion() + "-" + instance.getLoaderVersion();
Path forgeClientJar = instance.getPath().resolve("libraries")
.resolve("net/minecraftforge/forge")
.resolve(forgeVersion)
.resolve("forge-" + forgeVersion + "-client.jar");
if (Files.exists(forgeClientJar) && isValidJar(forgeClientJar)) {
String sep = System.getProperty("os.name").toLowerCase().contains("win") ? ";" : ":";
classpath = forgeClientJar.toAbsolutePath().toString() + sep + classpath;
System.out.println(ZAnsi.green(" Added forge client jar: " + forgeClientJar.getFileName()));
} else {
System.out.println(ZAnsi.yellow(" Forge client jar not found at " + forgeClientJar));
}
command.add("-cp");
String cpFile = writeClasspathFile(classpath);
command.add(cpFile);