Java Reference
In-Depth Information
Figure 14.17
Various options of the jar tool.
The c option is used for creating a new JAR file, and the x option is used for extracting
an existing JAR. I like to use the v option for verbose so I can see what the tool is doing.
The f option is used to specify the name of the new file. Another common option is m,
which is used to add a manifest file to the JAR. Manifest files are required for all JAR files,
and the jar tool will create one for you if you do not specify an existing manifest file using
the m option. For example, the following manifest file is used for a JAR file that contains an
application:
Manifest-Version: 1.0
Main-Class: com.javalicense.JeopardyGame
To demonstrate the jar tool, the following command line creates a new JAR file named
jeopardy.jar that contains the directory \com and all of its subdirectories, plus the text file
questions.txt:
jar -cvmf my_manifest.mf jeopardy.jar .\com questions.txt
Notice the order of the options m and f relative to the subsequent filenames: The m
appears before the f, and the name of the manifest file appears before the name of the
new file to create. The order in which the options appear is the order in which the respec-
tive filenames need to appear. For example, the following command creates the same JAR
file:
jar -cvfm jeopardy.jar my_manifest.mf .\com questions.txt
Figure 14.18 shows the verbose output of creating this JAR.
continued
Search WWH ::




Custom Search