Main-Classheader in the manifest, which has the general form:
classnameis the name of the class that is your application's entry point.
Recall that the entry point is a class having a method with
public static void main(String args).
After you have set the
Main-Class header in the manifest,
you then run the JAR file using the following form of the
java -jar JAR-name
mainmethod of the class specified in the
Main-Classheader is executed.
We want to execute the
main method in the class
MyClass in the package
when we run the JAR file.
We first create a text file named
with the following contents:
MyJar.jarby entering the following command:
jar cfm MyJar.jar Manifest.txt MyPackage/*.class
Manifest-Version: 1.0 Created-By: 1.6.0 (Sun Microsystems Inc.) Main-Class: MyPackage.MyClass
java -jar MyJar.jar
Main-Classattribute. It can be used while creating or updating a jar file. Use it to specify the application entry point without editing or creating the manifest file. For example, this command creates
Main-Classattribute value in the manifest is set to
jar cfe app.jar MyApp MyApp.class
You can directly invoke this application by running the following command:
java -jar app.jar
If the entrypoint class name is in a package it may use a '.' (dot)
character as the delimiter.
For example, if
Main.class is in a package called
foo the entry point can be specified in the following ways:
jar cfe Main.jar foo.Main foo/Main.class