CIT 597 Executable .jar Files
Fall 2002, David Matuszek

You can make a .jar file executable. What this means is that all you have to do to run your program is to double-click on the .jar file. Please do this for all future submissions; it's much easier for us to grade.

There are two parts to doing this:


The easy way: BlueJ

  1. Open your project in BlueJ, and make sure it runs correctly.
  2. From the Project menu, choose Export...
  3. In the dialog window that appears:
    1. Choose Store as jar file
    2. For the main class:, choose the class in your program that has the main method you want the program to start from (remember, any class may have a main method, so BlueJ doesn't know which one you want).
    3. Make sure include source is checked (necessary for grading purposes).
    4. Click Continue.
  4. In the next dialog window, choose a directory to put your jar file in, type a name for it where asks for a File Name: (the name should end in .jar), and click Create.

The not-too-difficult way: Manually

  1. If possible, collect all your .java files and .class files (and anything else you want to include) together in a single directory.
  2. Using a text editor, create a file (say, myManifest) containing the following lines:

          Manifest-Version: 1.0
          Main-Class: MyMainClass

    where MyMainClass is the name of the class containing the main method you want to use.
  3. From the command line, execute the command:

         jar cvfm myResult.jar myManifest *.java *.class

    where myResult.jar is the jar file you are trying to create, myManifest is the file you created in step 2, and everything else is the files you want to include.

The hard way: Forté

  1. Run Forté.
  2. From the main window (at the top), choose Help -> Contents.
  3. Choose Using the JAR Packager -> Creating a JAR File.
  4. Follow the instructions.

Executing an executable jar file:

There are two ways to execute the jar file:

To make jar files executable (Windows 98):

These instructions are for Windows 98. They aren't hard to adapt to Windows 2000; I don't know about the other assorted varieties of Windows.

In Windows file Explorer, choose View -> Folder Options..., then select the File Types tab. Check to see if there is a file type of Executable Jar File:

  1. Find your javaw.exe file and make a note of its location For example, mine is C:\Program Files\Java\j2re1.4.0\bin\javaw.exe.
  2. If there is already a file type of Executable Jar File:

  3. If there is not already a file type of Executable Jar File:

  4. Change the Application field to:
          C:\Program Files\Java\j2re1.4.0\bin\javaw.exe -jar "%1"
    where the part before -jar is the path you found in step 1.