I have a JAR file named helloworld.jar. In order to run it, I\'m executing the following command in a command-line window:
Steps:
1.) search for Java SE Runtime Environment on Google: https://www.google.com/search?q=Java+SE+Runtime+Environment
2.) install the appropriate version onto your computer
In Windows Vista or Windows 7, the manual file association editor has been removed.
The easiest way is to run Jarfix, a tiny but powerful freeware tool. Just run it and your Java apps is back... double-clickable again.
An interesting side effect of this causes a problem when starting runnable jar files in the command prompt.
If you try (in a command prompt):
jarfile.jar parameter
No joy, because this is being translated to the following (which doesn't work):
javaw.exe -jar jarfile.jar parameter
However, the following command does work:
java.exe -jar jarfile.jar parameter
If you change the association in file manager as described above to:
"C:\Program Files\Java\j2re1.4.2_04\bin\java.exe" -jar "%1" %*
Then you can type:
jarfile.jar parameter
in the command prompt and it will now work!
EDIT:(However you then get a black console window when you run a form based (non console) Java app, so this is not an ideal solution)
If you run these jar files by double clicking them in windows, no parameters will be passed so your Java code needs to handle the stack overflow exception and include a "press a key" function at the end or the window will just disappear.
In order to pass a parameter in windows you have to create a shortcut to the jar file, which includes the parameter in the target line (right click on the shortcut and select properties) you can not add parameters to the jar file icon itself in this way.
There isn't a single, consistent solution here, but you would have the same problem with any other console application.
There is a windows freeware application called "bat to exe" which you can use to create an exe file from a .bat file with the apropriate command line in it. you can also embed the jar file in the exe with this application, and make it clean it up when it has finished running, so this may be a more elegant solution.
Making a start.bat was the only thing that worked for me.
open a text document and enter. java -jar whatever yours is called .jar
save as start.bat in the same folder as the .jar file you want to execute. and then run the. bat
Besides all of the other suggestions, there is one other thing you need to consider. Is your helloworld.jar a console program? If it is, then I don't believe you'll be able to make it into a double-clickable jar file. Console programs use the regular cmd.exe shell window for their input and output. Usually the jar "launcher" is bound to javaw.exe which doesn't create a command-shell window.
In regedit, open HKEY_CLASSES_ROOT\Applications\java.exe\shell\open\command
Double click on default on the left and add -jar between the java.exe
path and the "%1
" argument.