March 4, 2021
Hot Topics:

Java ARchive (JAR) Files 101

  • By Sridhar M S
  • Send Email »
  • More Articles »

JAR File in App Deployment

Now that you have a JAR file, you may want to use it as part of your application deployment process. Typically, you will form many JARs for different application components (client and server, for instance) and use them in an application.

The class MyApplication.java, which is bundled in the JAR file, is only an example. For actual deployments, you would bundle only the .class files instead of the .java files. Assuming that you have now bundled the MyApplication.class file, you can execute this class file. The java command has an option for this.

The command java –jar –MyApplication.jar would result in the following output:

Failed to load Main-Class manifest attribute from

For this command to work as expected, you need to do one important thing. The MANIFEST.MF in the MyApplication.jar file has to be updated with the following line:

Main-Class: com.mycomp.demo.MyApplication

Now the modified MANIFEST.MF file will have the following contents:

Manifest-Version: 1.0
Created-By: 1.5.0_19 (Sun Microsystems Inc.)
Main-Class: com.mycomp.demo.MyApplication

Also, in the Java ARchive_src.zip code download, the MyApplication.java file is updated as follows with the string main method of MyApplication:

package com.mycomp.demo;
public class MyApplication
    public static void main(String args[])
        System.out.println("main method of MyApplication.");

The addition of the main class is also referred to as defining the entry point for the JAR file.

To update your MyApplication.jar file, repackage the class file and the updated MANIFEST.MF file. Now, execute the command java –jar –MyApplication.jar to get the desired result.

Page 2 of 3

This article was originally published on September 30, 2009

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date