S LogoS Logo

Executable Jar Files

The concept of a Jar file (Java Archive) is simple. It is just a zip file with the extension ".jar" instead of ".zip". An executable jar file is a regular jar file, which contains a text file called MANIFEST.MF in a directory called META-INF. This file can contain among other things, a line which tells the Java Virtual Machine which class to execute. For example:

Main-Class: SkinnyMessenger

instructs the JVM to execute the main method of the class called SkinnyMessenger

To run an executable jar file called SkinnyMessenger.jar from the command line, type:

java -jar SkinnyMessenger.jar

You must not forget to add the ".jar" on the end, otherwise it will not work. If you don't want terminal output, then you can type:

javaw -jar SkinnyMessenger.jar

Setup

If you are running Windows, and have Java installed, then your system should be set up, so that you can double-click on a jar file to run it. Sometimes however, this does not happen.

Here's how to find out if your computer is set up correctly:

  1. Download the test file.

    If your system is set up correctly, the file should have this icon. Jar file icon

  2. Double-click on the file. You may have to wait a little while for it to load. Although it is only a small program, it takes some time for the JVM to load the first time, especially on slower machines.
  3. Program outputIf you see something like the picture on the right, then it worked, and your system is set up correctly. If you are confronted with a dialog box asking you which program you would like to open the file with, then your system is not set up correctly.
Here is how to fix it:
  1. Firstly make sure that you have installed either a Java Runtime Environment (JRE) or Java Developers Kit (JDK or J2SDK, they are the same thing). If you only want to run programs, then get the JRE, but if you want to write/modify programs, you will need the JDK. You can get them both here. If you're not sure if you already have it, download and install it anyway, at least that way you will have the latest version.
  2. If you have just installed a JDK or JRE then run the above test again. If it still doesn't work, proceede to the next step.
  3. Now, go to "My Computer" and click "Tools" followed by "Folder Options...".
  4. Click on the "File Types tab".
  5. Click on the "New" button.

    The procedure differs slightly from here depending on which version of Windows you are running, but they are all fairly similar, so what I say here may be slightly different on your computer. These instructions work under WindowsXP. Instructions for other versions are coming soon.

  6. Enter "jar" in the box labelled "File extension:".
  7. Click "Ok".
  8. Click "Advanced".
  9. In the box next to the "Change Icon..." button enter "Executable JAR file".
  10. Click "New...".
  11. In the box labeled "Action" enter "&Open".
  12. Now click the "Browse..." button
  13. Navigate to the location that you installed Java into (for the 1.4.0 JDK this will be something like "C:\j2sdk1.4.0_01\").
  14. Go into the "bin" directory and select "javaw"
  15. Click "Open"
  16. In the box labeled "Application used to perform action" put a quote (") at the beginning and end.
  17. Now at the end of the box put a space ( ) followed by -jar %1
  18. Dialog screenshotThe window should look something like the picture on the right.
  19. Ok all boxes.
  20. Run the test again, and hopefully it should work this time.