I made a very simple program with Eclipse Indigo and exported it as an executable jar to my desktop. If I use the command \"java -jar SayHello.jar\", the program runs, but if I
For Java on Windows (which you didn't actually specify) the default action when doubleclicking a .jar
file, as you found, is to run it with the javaw
JVM which is "GUI" mode and anything the code writes to System.out
is discarded. The java
JVM does output to the console window, but if that window was created by double-clicking it vanishes as soon as the code exits, as you found.
Note the "association" for .jar
(in HKCR\jarfile\shell\open\command
) must be
"(YOUR_JREDIR_usually_progfiles-arch-jre-version)\bin\javaw.exe" -jar "%1" %*
or java.exe
for console, in either case with the -jar
. I don't believe control panel will set extra flag arguments like that correctly, and that would account for the "cannot find main class".
A batch file with two lines java -jar myjar
and then pause
when doubleclicked should run the class and when it exits wait until you press any key before destroying the window. You can instead use timeout numseconds
to limit the wait.
ADDED: Double Clicking JAR file does not open Command Prompt has another way to keep the console window from disappearing: use cmd /s /k
instead of a batch file.