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?
Asked
Active
Viewed 260 times
0
-
So, it works or not? You say it runs fine from the command line – OneCricketeer Sep 21 '16 at 01:31
-
What version of java are you using? Which version of Windows are you using? – Raghav Sep 21 '16 at 01:43
-
What I was saying was, It works in the cmd but I can't get it to work when you double click the .jar file. And I'm running windows 10 and java 8. Sorry about the lack of information, new to this stuff! – codenameveg Sep 21 '16 at 01:54
-
@codenameveg check comments of this answer http://stackoverflow.com/a/8511277/1166537 . – Raghav Sep 21 '16 at 03:55
1 Answers
0
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();
}
-
This didn't work, I guess I should've added that I already have it ask you to enter a number before it ends. – codenameveg Sep 21 '16 at 01:56
-
1You could try adding some code at the end of your execution logic to wait a few seconds just to confirm whether this is the issue. `Thread.sleep(10000);` will make it wait 10 seconds. – D.B. Sep 21 '16 at 02:29
-
The best fix I've found thus far is creating a .bat file to run the command java -jar ___.jar as well as adding the "Press enter to continue" thing that jtwaller suggested. Ill continue to search for a complete fix. – codenameveg Sep 21 '16 at 19:06
-
Hey jtwaller, any chance you could repost that "press enter to exit" line of code, I am on a different computer and I can't find it. – codenameveg Sep 23 '16 at 23:31
-
Sure, added above. Please don't forget to accept my answer if we have solved the problem. (It's the checkmark under the up and down arrows to the side of my submission.) – jtwaller Sep 24 '16 at 00:06