executable jar files : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

executable jar files

Executing Jar Files

One of the most useful associations to set up is to make *.jar files executable with java.exe (see below for details how). Then you can just type the name of the jar on the command line to start it executing. After you have built the Main-Class entry and set up an association of the *.jar extension to C:\Program Files\java\jre1.8.0_131\bin\java.exe, all you need to do to run the jar is:

converter.jar
or
java.exe -jar converter.jar
Watch out. Java install sets the association back to javaw.exe, no console! If you get unhandled Exceptions, you will never find out about the errors, stack dumps or any other error messages!

To run the jar in an Applet, see Applet for some sample HTML (Hypertext Markup Language) or see

on doing it.

The associations for *.jar and *.jnlp are fragile. They mysteriously change to obsolete versions, or javaw.exe version without a console or even unrelated programs like Winzip.exe. Using the java.exe -jar myjar.jar syntax in your bat/btm files rather is more robust than myjar.jar. It works even when the associations are corrupted.

Making Jar Files Double Clickable

In XP, W2003, Vista, W2008, W7-32, W7-64, W8-32, W8-64, W2012, W10-32 and W10-64 you can use the method shown below:.

  1. Download Johann Löfflmann’s Jarfix.exe.
  2. Run

    jarfix.exe

    if you want to hook up your 32-bit JRE or

    jarfix.exe /64

    if you want to hook up your 64-bit JRE. It says on does not work on W10-32 and W10-64, but it does.

  3. This will invoke C:\Program Files\java\jre1.8.0_131\bin\javaw.exe when you run someapp.jar or double click the someapp.jar file.
  4. This is Oracle’s official way of doing things — throw away all the console output. I find this idiotic. You want the output. You want the error messages. You want to invoke C:\Program Files\java\jre1.8.0_131\bin\java.exe instead.
  5. To fix the problem, invoke regedit.exe at a run-as-administrator prompt.
  6. Look for:

    [HKEY_CLASSES_ROOT\jarfile\shell\open\command]
    "C:\Program Files\Java\jre1.8.0_131\bin\javaw.exe" -jar "%1" %*

    and change it to:

    [HKEY_CLASSES_ROOT\jarfile\shell\open\command]
    "C:\Program Files\Java\jre1.8.0_131\bin\java.exe" -jar "%1" %*
  7. Alternatively, you might configure a custom jarfix.ini file that uses java.exe in place of javaw.exe with the /c option.
  8. You also need a config file if your JRE is not on C: or if you have multiple JREs. The loeffliman.net website gives instructions on composing an ini file. You can also use REGEDIT to patch the generated registry entry manually under run-as-administrator.

There are lots of other methods people have recommended, but this is the only one I found that works.


This page is posted
on the web at:

http://mindprod.com/jgloss/executablejar.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\executablejar.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[18.119.162.226]
You are visitor number