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.


The full .bat is as such.

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- --nogui

Error 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.exe

I 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.

New contributor
Lahyte is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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>

  • Hi! Thanks for the reply. Sorry for the miscommunication. The bat file does have the path to forge jar. I've included the full bat file in the post. Thanks! – Lahyte Jun 10 at 4:11
  • @Laythe The command you have written makes no sense at all. You execute java <some arguments > "java.exe" -jar <forge dll> . That is not how the java command works, it doesn't take another java executable as parameter. – Polygnome Jun 11 at 6:53
  • Wait what? It doesn't take 2 java executables as parameters? I tried shifting the 1.8 java.exe into the server folder and ran java -Xms8G -Xmx8G -jar forge-1.12.2- --nogui`. It worked. It used the 1.8 java.exe over the 1.16 java.exe. – Lahyte 2 days ago
  • @Lahyte If you type in java in the shell (or a script), what happen is that Windows needs to find an executable named Java. The first place Windows looks at is the current folder, then Windows checks the PATH. If you copy the java.exe of 1.8 into the server folder, and then execute the script in that folder, Windows will first find the 1.8 executable and not look further. In technical terms, that executable will shadow your 16 executable in your path. Crucially, this depends on the working directory in which you execute the script being the one with your java 1.8 exec. – Polygnome yesterday

Potential answer


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

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- --nogui

When 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 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(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 more


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.

New contributor
Lahyte is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Lahyte is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.