Problem
I want to run two servers, one in 1.17 using Java 16 and the other in 1.12.2 using Java 8.
The argument I want to use in the .bat file is "C:\Program Files\Java\jre1.8.0_291\lib" -jar but it doesn't work.
.bat
The full .bat is as such.
@ECHO OFF
java -Xms10G -Xmx10G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=8 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=true -Daikars.new.flags=true "C:\Program Files\Java\jre1.8.0_291\bin\java.exe" -jar forge-1.12.2-14.23.5.2855.jar --nogui
pauseError message
The error given is:
Error: Could not find or load main class C:\Program Files\Java\jre1.8.0_291\bin\java.exe
Caused by: java.lang.ClassNotFoundException: C:\Program Files\Java\jre1.8.0_291\bin\java.exeI don't know how to resolve the error of the java class not being found.
Additional details
I am running JRE 16 and Java 8 on the same computer. Only the 1.17 servers start with this installation set up.
The 1.12.2 server starts when I uninstall JRE 16.
2 Answers
You need to use the correct binaries.
Suppose Java 15 is in your PATH variable. Then executing the plain java command will execute with the Java 15 binary.
C:\Program Files\Java\jre1.8.0_291\bin\java.exe is your java 8 binary.
Thus, to execute forge on Java 8, you don't want to execute the plain java command, since that is java 15. You will need to qualify the whole path to your Java 8 executable, with the command:
C:\Program Files\Java\jre1.8.0_291\bin\java.exe -jar <path to forge jar>
Potential answer
Context
I've installed 2 versions of java, 8 and 16. When I type java -version in command prompt, java 16 shows up.
The following is my .bat file for forge 1.12.2
@ECHO OFF
java -Xms10G -Xmx10G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=8 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=true -Daikars.new.flags=true -jar forge-1.12.2-14.23.5.2855.jar --nogui
pauseWhen trying to run a 1.12.2 forger server in this state, the following error message appears.
A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException at (Native Method) at (NativeMethodAccessorImpl.java:78) at (DelegatingMethodAccessorImpl.java:43) at (Method.java:567) at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:70) at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:34)
Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap') at net.minecraft.launchwrapper.Launch.<init>(Launch.java:34) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) ... 6 moreSolution?
I take the java.exe from where I've installed Java 8: C:\Program Files\Java\jre1.8.0_291\bin.
I put it inside my minecraft folder, in the same file level as the forge jar and bat file.
I use the same .bat as shown above, no modifications.
I run it, and the server turns on.