Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu Minecraft Server java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader

Im trying to run my modded mc server. It works on wondows but when I try to run it on ubuntu it gives me this error:

    saif@Saif-Ubuntu:~/Desktop/Minecraft Server$ java -Xmx2048M -Xms2048M -jar forge-1.12.2- 
14.23.5.2854.jar
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:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    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 tried uding jdk 11 and jdk 8 but for all I can tell neither work. Anyone know anything I can try?

like image 709
Saif Abdein Avatar asked Dec 11 '25 07:12

Saif Abdein


2 Answers

This issue occurs when you don't use JDK 8, please try using it again, uninstall JDK 11 and check your JDK version with java -version.

I figured out how to switch java versions without uninstalling any:

sudo update-alternatives --config java

Thanks to Joseph Sible, Novarch, and Likqez for pushing me in the right direction.

like image 27
Saif Abdein Avatar answered Dec 12 '25 20:12

Saif Abdein