I have a JAR file named helloworld.jar. In order to run it, I\'m executing the following command in a command-line window:
First set path on cmd(command prompt):
set path="C:\Program Files\Java\jre6\bin"
then type
java -jar yourProgramname.jar
Unfortunatelly, it is not so easy as Microsoft has removed advanced file association dialog in recent Windows editions. - With newer Windows versions you may only specify the application that is going to be used to open .jar file.
Fixing .jar file opening on Windows requires two steps.
Open the Control Panel, and chose "Default Programs -> Set Associations". Find .jar extension (Executable JAR file) there, and pick Java as default program to open this extension. It will probably be listed as "Java Platform(SE)". A faster alternative perhaps is straightforward right-click on a .jar file, and then change associated program by clicking on the "Change..." button.
Now open the regedit, and open the HKEY_CLASSES_ROOT\jarfile\shell\open\command
key. Luckilly for us, we may specify parameters there for the (Default)
value. On my Windows system it looks like: C:\app\32\jre7\bin\javaw.exe" -jar "%1" %*
but in most cases it is the following string: C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
NOTES:
java.exe
there as it will open the shell window.I had the same problem in Windows 10. I fixed it using righ-click on the "helloworld.jar" and go to properties and click on change button under "Opens with:" and select "Look for another app on this PC". In the "Open with..." dialog box, go to your Java folder location on your PC and open corresponding jdk folder and then open the bin folder and select "javaw.exe" from there. Then next time your "helloworld.jar" will open the normal way.
Usual java location example : "C:\Program Files (x86)\Java\jdk1.8.0_111\bin".
I´m running Windows 7 x64 and was unable to use any of these fixes.
This one worked for me afterall:
http://thepanz.netsons.org/post/windows7-jar-file-association-broken-with-nokia-ovi
There is an archive which you can download containing a .bat file to run, but check the path of the actual javaw.exe!!!!
If you use eclipse for making your java files, you can choose to export it as a runnable jar file. I did this with my programs and I can just click on the jar and it will run just like that. This will work on both windows, as well as os x.
use
.bat
file:
Put your command in a .bat file. here, your command will be java -jar path\yourJarName.jar
.
Something like: java -jar C:\workspace\myApplication.jar
Save it and double click on bat file to run your jar.