Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
If you have an application bundled in a JAR file, you need some way to indicate which class within the JAR file is your application's entry point. You provide this information with the Main-Class header in the manifest, which has the general form:The value classname is the name of the class that is your application's entry point.Main-Class: classnameRecall that the entry point is a class having a method with signature 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 command:
The main method of the class specified in the Main-Class header is executed.java -jar JAR-name
We want to execute the main method in the class MyClass in the package MyPackage when we run the JAR file.We first create a text file named Manifest.txt with the following contents:
Main-Class: MyPackage.MyClassWe then create a JAR file named MyJar.jar by entering the following command:
Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.This creates the JAR file with a manifest with the following contents:jar cfm MyJar.jar Manifest.txt MyPackage/*.classWhen you run the JAR file with the following command, the main method of MyClass executes:Manifest-Version: 1.0 Created-By: 1.5.0_01 (Sun Microsystems Inc.) Main-Class: MyPackage.MyClassjava -jar MyJar.jar
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.