I followed about 10 different tutorials and none of them seemed to do the trick, my runnable jar file just isn\'t working.
My game runs fine when I
I assume you're making a GUI application, and launching the Jar by clicking on it? Many times if a GUI application has an error at startup, it doesn't visibly do anything, like pop an error message, because it hasn't had a chance to build any sort of GUI to report the error to yet. I would guess that something you changed causes an exception at startup, and that message is not visible because you're launching the jar by clicking on it.
If you run the Jar from the terminal instead (spotlight: "terminal") you will be able to see the stack trace that's preventing your Jar from running, and hopefully that will help you debug further.
$ cd directory/of/jar
$ java -jar name_of_jar.jar
.... stack trace should appear here, or program should run
You can also try to catch the exception in your main
method and display a GUI alert, however this doesn't work if the exception is raised before the main
method starts (e.g. during class loading). In other words it's a nice-to-have, but doesn't totally solve the problem. You may still need to run the Jar from the command line.
public static void main(String[] args) {
try {
// body of main method goes here, including any other error handling
} catch (Throwable t) {
JOptionPane.showMessageDialog(
null, t.getClass().getSimpleName() + ": " + t.getMessage());
throw t; // don't suppress Throwable
}
}
To run a .jar file, in command line write:
java -jar 'jar_file'.jar
Where 'jar_file'
is the name of your jar file without any quotes. In your case it appears to be run.jar
.
.jar
files are .zip
archives, which can confuse the operating system
Jar file format
Check your Java version.
If your program is compiled against Java 8 and the version of Java on your PC is Java 9 or higher then it may be not working.
Try to delete the .class files from the bin folder and restart the project and clean the project. It is issue with eclipse.Even i was facing the same issue then i deleted the files and followed the mentioned process.