Running a Java .jar File: 7 Steps (with Pictures)

Table of contents:

Running a Java .jar File: 7 Steps (with Pictures)
Running a Java .jar File: 7 Steps (with Pictures)

.jar files are used for archiving and extracting archives. One of the essential properties of jar files is the ability to compress without data loss. Do you want to know how to execute such a file? Here's how.


Run a.Jar Java File Step 1

Step 1. Make sure you have Java installed on your system

Check this by entering in the command prompt java - version. If you don't have the latest version of Java, update it before continuing.

Run a.Jar Java File Step 2

Step 2. Making a.jar file executable

A.jar file can be made executable by collecting the so-called "class files" of your Java application. JVM (Java Virtual Machine) compilers understand these formats..jar files are run from javaw (Java web start). You need to set a so-called "entry point" within the.jar file for this. (An entry point is a class that contains the main function of your application) You can set the entry point using the Manifest file. Here's how to do this:

  • The Jar tool automatically sets meta-inf/ as the path of the.jar file. When you open such a Manifest file it should say "Manifest-Version: 1.0, Created-By: 1.6.0 (Sun Microsystems Inc)"

  • Create a text file to add to the manifest. Type in Main Class: [Package Name].[Class Name], filling in the specific information in the brackets. (This in the form of an attribute value pair.)

  • Enter this command in the command prompt to modify the Manifest file to embed the application entry point. Again adjust the part in brackets to your specific filenames: jar cfm [jar filename] [manifest appendix] [input files]

  • Check your Manifest file. After setting this entry point, it should now say: "Manifest-Version: 1.0, Created-By: 1.6.0 (Sun Microsystems Inc), Main Class: [Package Name].[Class Name]"

  • Alternatively, you can set the entry point using the.jar tool. This overrides the Main-class attribute in the Manifest file. Enter the following command: jar cfe [jar file name] [Package Name] [Class Name with main function]

    Run a.Jar Java File Step 3

    Step 3. Run your.jar file

    Run your.jar file with the following command (which executes the main method of your java application): java -jar [Jar file name]

    Run a.Jar Java File Step 4

    Step 4. Set the.jar file to become executable by double clicking on it (optional)

    To open a.jar file by double clicking on it, you need to change the directory to the location of the javaw (java web start) executable (.exe). Type the following command in the command prompt: C:\Program Files\Java\j2rex.y.z\bin\javaw.exe" -jar "%1" %*

    Method 1 of 1: Running a.jar file in Linux

    Run a.Jar Java File Step 5

    Step 1. Open the terminal

    Double clicking on a.jar file in Linux opens it in a zip archive application that will display the contents of the.jar file. Instead, right-click on it and select "Open Terminal".

    Run a.Jar Java File Step 6

    Step 2. Run the following command: $>java -jar [jar filename]

    Run a.Jar Java File Step 7

    Step 3. Open your.jar file by double clicking on it (optional)

    To open a.jar file by double-clicking it, you may need to change the file type association (similar to the instructions for Windows), depending on your Linux distribution.

    • Make sure the command above works.

    • Type the following command into the terminal: $>/usr/lib/jvm/jre-1.6.0-sun/bin/java -jar %f

    • Point the path to the location where Java is installed on your system.


      • Java programs work on all platforms. If it doesn't work it is not programmed properly or it is a highly specialized program that relies on system resources or is dependent on other programs.
      • Inside the folder containing javaw.exe is a program called javaws.exe. Don't confuse them - javaw.exe is to run java programs in Windows and javaws.exe means JAVA w eb starts.
      • A.jar file could possibly be a program or a library. If it's a library (it doesn't have an executable class in it), there's no point trying to run on it.
      • A.jar file may depend on other files to work properly. (Similar to.exe files) If these are not included in the "classpath", the program may not work.

Popular by topic