codenameveg codenameveg - 2 months ago 23
Java Question

Exported eclipse runnable .jar will not run

So i'm pretty new to programming and java and I finished a Prime number program. It runs in the cmd and doesn't use any GUI. When I try to double click it the cmd window pops up for like a frame then disappears. When I try to run it with the command "java -jar _____.jar" it works fine and it works fine in eclipse. Earlier I was getting an error saying that I don't have a main manifest attribute but it seemed to go away. If you guys know the fix to the main attribute thing I could try that. Other than that anyone have any ideas?

Answer

Here's a link to a previous similar question. They have some good solutions there.

A simple one to try starting out is JarFix which will re-associate .jar files with the right java exe.

If your program is immediately closing upon running, try adding snippet at the end of it to keep the process alive.

System.out.println("Press enter to close.");
try {
    System.in.read();
} catch (Exception e) {
    e.printStackTrace();
}