How to Create an executable JAR file

Here is the general procedure for creating an executable JAR:

  1. Compile your java code, generating all of the program’s class files.
  2. Create a manifest file containing the following 2 lines:
    Manifest-Version: 1.0
    Main-Class: name of class containing main

    The name of the file should end with the .mf suffix but it is not compulsory. It is important that the file ends with a blank line.

  3. To create the JAR, type the following command:
    jar cmf manifest-file jar-file input-files

    The input-files must include any class files, images, sounds, etc. that your program uses. Optionally, you can include the program’s .java files in the JAR.

  4. To view the contents of the JAR, type:
    jar tf jar-file
  5. Execute the application from the command line by typing:
    java -jar jar-file

    If the application is GUI-based, you can also launch it by double-clicking the JAR file.


A simple example.

Let’s say we wanted to distribute the simple program as a JAR.

First, we create a text file named which contains:

Manifest-Version: 1.0
Main-Class: Hello

Then, we create the archive by typing:

jar cmf Hello.jar Hello.class

and run it by typing:

java -jar Hello.jar



Manohar Bhattarai (मनोहर भट्टराई)


I am Manohar Bhattarai, a vivid java programmer. I am a keen Linux user. I currently boot Ubuntu Linux. I am a Free/Libre Open Source Software enthusiast.

Posted in Java Tagged with: , , , , , , , , , , , ,
0 comments on “How to Create an executable JAR file
2 Pings/Trackbacks for "How to Create an executable JAR file"
  1. Sysfader IExplore Exe Application Error | Windows Errors Fix says:

    […] How to Create an executable JAR file « Mano&#104&#97&#114 Bhattarai […]

  2. […] have moved this post to my new blog site. Click here to get to the […]

Leave a Reply