I am making a 2d game, which I have compiled into a .jar to test if it works.
When in run the jar file with java -jar
command I get the following error:
Error: Could not find or load main class com.grizeldi.splatoon.Main
I know that there are many solutions here on StackOveflow, but I have tried updating java, messing with -cp... Nothing worked so far.
Code: github repo
Help anyone?
EDIT1: I have my code on a USB stick, but I have tried moving it to C: and D: but nothing worked. EDIT2: I have added the .jar on the github.
One way is to update the Manifest with the classpath to the other jars:
Class-Path: lib.jar
An alternative is to add the contents of the jars your main jar depends on to your main jar, so you have only one jar file. Make sure you don't add the jars themselves to the main jar, as nested jars won't work.
When dealing with native libraries (.so
, .dll
), simply place these in the same directory as the jar. The downside of this is that you have multiple files.
In that case, it might be easiest to just add a startup script (.sh
, .bat
), specifying the classpath and the classname of Main, aswell as a -Djava.library.path
.
There is also another way: extract the native library from the jar at runtime, save it to a temporary location, and load it explicitly. See here for more info on that.