Double Clicking JAR file does not open Command Prompt

Solution 1:

When you use the javaw association, it does not create a command window, and swallows all the System.out and System.err invocations.

You should reassociate your .jar file with the java binary, which should display the requisite command window.

If you used the simple Open With... option, it will have omitted the -jar option from the command line.

Open up an administrator command window (this is needed if you're using Vista or Windows 7 with UAC enabled) and do:

assoc .jar=jarfileterm
ftype jarfileterm="C:\Program Files\Java\jre7\bin\java.exe" -jar "%1" %*

In your case, you should replace the C:\Program Files\Java\jre7\bin\java.exe path with the one for your install of the jre.

When you double-click following this, then it should run correctly.

You can add another ftype:

ftype jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*

again substituting the path to the javaw binary with the one that's for your system.

You should now be able to toggle between windowed and non-windowed by alternately choosing assoc .jar=jarfileterm and assoc .jar=jarfile

If you want to keep the command window around after running the .jar, then you surround the calling of the java command with a cmd /s /k viz:

ftype jarfileterm=cmd /s /k ""C:\Program Files\Java\jre7\bin\java.exe" -jar "%1" %*"
assoc .jar=jarfileterm

If these commands worked, then double clicking on the jar file will cause a command window to pop-up and persist.

You cannot set a complex enough command line with either Open With... or using Default Programs that will allow the jar file to run. If you have successfully tried all these efforts ftype and assoc commands and it still doesn't work, then you will need to peel out the registry editor.

Launch regedit, and search for a key called .jar under HKEY_CLASSES_ROOT - this should result in a single value underneath it called (Default) with a value, if your ftype command invocations worked, then it should read jarfileterm. If it didn't work, then you're looking at an association that may have been created by another application (I don't know if the java updater replaces these entries, but if it does, then this could be the issue)

You need to next look for this key in the HKEY_CLASSES_ROOT. It will find this entry, which should contain the a key Shell (i.e. expand the folder jarfileterm and it should reveal another folder Shell), which contains a key Open which contains a key Command which contains a (Default) value that should contain the invocation command for launching .jar files. This command should match the last ftype jarfileterm=... entries that you typed in. If it doesn't then you should make it match one of the cmd /s /k or "c:\program files\java\jre7\bin\java.exe" options (depending on if you want to persist the command window in the event of an error in launching or not)

Solution 2:

May be your .jar file has binded with any other default program, Right click and open with 'Java(TM) Platform SE binary'. This should work if have a executable jar file.