How to Create an Executable Java Archive (JAR)

There has been an increasing interest in how to create a .jar file that is directly executable on a computer which has the Java Runtime Engine (JRE) installed.

Here are the instructions:

  1. Assuming you have created a Java application in a Java project (folder) in Sun ONE Studio:



    Say you now want to package myProject.
  2. Right-click on your mounted filesystem (e.g., C:\forte_jdk\projects\sampledir\examples, above); the following menu appears:



    In this menu, highlight (do not select) the "New" item; the following sub-menu appears:



    In this sub-menu, highlight the "Jar Packager" item; the following sub-menu appears:



    Select this single menu item.
  3. Once you select to create a new JAR Recipe, the following New JAR Recipe Wizard appears:



    In this first pane of the Wizard, enter the Recipe name (it's a good idea to use the package name; e.g., myProject).
    BTW, you do not have to change the Jar Recipe Filter to <all files>.

    The first pane of the Wizard now looks like:



    Click the "Next >" button when ready.
  4. The second pane of this Wizard now appears:



    In the left list, bring the contents of the mounted filesystem into view:



    In this left list, select the package (e.g., "myProject") to be added to the archive.
    Click the "Add >" button (now active) to add the folder to the JAR (adding a package (folder) adds all the enclosed files as well):



    Click the "Next >" button when ready.
  5. In the third pane of the Wizard, you are given the option to modify the JAR Recipe Contents.
    For now, you can safely ignore this pane, and click the "Next >" button.
  6. In the fourth (last) pane of the Wizard, you are asked for the JAR Manifest:



    Click on the "Generate" button:



    You now have to add one additional line to the Manifest, to tell it which object class to execute initially (i.e., which object class represents the main Application).
    As the application has been created in a package, the full specification must be used:



    Finally, click the "Finish" button.
  7. Your JAR Recipe now appears in the FileSystem Explorer:


  8. You now have to create the JAR itself.
    Right-click on the JAR Recipe in the FileSystem Explorer:



    From the above menu that appears, select the "Compile" option to compile the JAR recipe into a JAR, or the "Execute" option to compile and then execute the application.
  9. Your JAR has now been created as two files, visible in the desktop or in Windows Explorer:



    You can now execute the file "myProject.jar" by simply executing (i.e., launching) it on the desktop.

    In fact, you can totally shut down ONE Studio and execute the file.

    Also, you can e-mail it to friends and they can execute it on their machines, assuming those machines have the JRE installed.

Fun, isn't it?

NJB