Java Reference
In-Depth Information
Figure 9-3.
Compiling the source into the classes directory
Creating a Manifest File
Now you'll want to create a manifest file. This file will be packaged in your project's JAR file
and used by the JVM to load the correct class and run the application. The key entry in the
manifest file is the class name of the main method you want to execute when running the
application. In our case, this is the
ApplicationRunner
class in the
gui
package.
The contents of the manifest file are minimal. Insert the following two lines of code and
save them in a new file called
Manifest.mf
. We have placed the manifest file in the root direc-
tory,
dennysDVDs2.0
.
Manifest-Version: 1.0
Main-Class: sampleproject.gui.ApplicationRunner
Note
The name of the manifest file can be anything you like if you are using Sun's
jar
tool to create the
JAR file. We will go into this in more detail when we describe using the
jar
tool in the section “Packaging
the Application” later in this chapter. If you are not using Sun's
jar
tool (there is really no reason not to use
it, though), then the final manifest file
must
be named
MANIFEST.MF
and must be placed in the
META.INF
directory, which must be in the root directory of the JAR file.
■
The location of the manifest file comes into play when we actually create a JAR file con-
taining our project's class files. All JAR files contain manifests, and the manifest can be used to
specify many attributes for the JAR file. Some of the more common attributes are shown in
Table 9-1.