Problems creating a start.command file

Ok so since sponge disables the default minecraft GUI I was trying to script a shell that would execute the server in terminal. After fixing the permissions I still encounter an error which I believe is caused by my default java version. Pretty sure I need to be on 8 not 11. This is the output I get every time I run the start.command. Does anyone know how to fix this? Possibly how to switch default java versions on Mac?

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:64)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:564)

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.(Launch.java:34)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

… 6 more

logout

Saving session…

…copying shared history…

…saving history…truncating history files…

…completed.

[Process completed]

Yep thats the not java 8 error.

When it comes to what application get the command for any application on mac, windows or linux, its based upon what the command shell can access first. It typically searches your current folder for a application called java, failing that it will use the path system.

So you have two options. The first is to change the Java_Home variable which is the path to the java application. Currently it will be set to the java 11, if you change it to the Java 8 location that will change the java command to 8.

The other option is one I have only used in windows, not Linux nor Mac and that it running the specific java application though the shell. In windows you did this by replacing ‘java’ in the command to “'Path_to_java”’ (in quotes). This has the advantage that you only need to do it once (you only need to do the other way one if you dont need java 11)