Combines multiple files into a single JAR archive file.
SYNOPSIS
jar [ options ] [manifest] destination input-file [input-files]
DESCRIPTION
The jar tool is a java application that combines multiple files
into a single JAR archive file. jar is a general-purpose
archiving and compression tool, based on ZIP and the ZLIB compression format.
However, jar was designed mainly to facilitate the packaging of
java applets or applications into a single archive. When the
components of an applet or application (.class files, images and
sounds) are combined into a single archive, they may be downloaded by
a java agent (like a browser) in a single HTTP transaction, rather
than requiring a new connection for each piece. This dramatically
improves download times. jar also compresses files and so further
improves download time. In addition, it allows individual entries in a
file to be signed by the applet author so that their origin can be
authenticated. The syntax for the jar tool is almost identical to the
syntax for the tar command. A jar archive can be
use as a class path entry, whether it
is compressed or not.
The 3 types of input files for the jar tool are
manifest file (optional)
destination jar file
files to be archived
Typical usage is
% jar cf myjarfile *.class
In this example, all the class files in the current directory are
placed into the file named "myjarfile". A manifest file is
automatically generated by the jar tool and is always the first entry
in the jar file. By default, it is named META-INF/MANIFEST.MF. The
manifest file is the place where any meta-information about the
archive is stored. Refer to the manifest specification for
details about how meta-information is stored in the manifest file.
If you have a pre-existing manifest file that you want the jar tool to
use for the new jar archive, you can specify it using the -m option:
% jar cmf myManifestFile myJarFile *.class
Note that when you specify "cfm" instead of "cmf" (i.e., you
invert the order of the "m" and "f" options), you need to specify the
name of the jar archive first, followed by the name of the manifest
file:
% jar cfm myJarFile myManifestFile *.class
The manifest uses RFC822 ascii format, so it is easy to view and process
the manifest-file contents.
Examples of using the Jar tool to operate on Jar files and Jar file
manifests are provided below
and in the Jar trail of the Java Tutorial.
You can use an argument beginning with the character '@' to
specify a file containing additional arguments, one argument per line.
These arguments are inserted into the command line at the position
of the '@<filename>' argument.
c
Creates a new or empty archive on the standard output.
t
Lists the table of contents from standard output.
x file
Extracts all files, or just the named files, from standard input. If
file is omitted, then all files are extracted; otherwise, only
the specified file or files are extracted.
f
The second argument specifies a jar file to process. In the case of creation,
this refers to the name of the jar file to be created (instead of on stdout).
For table or xtract, the second
argument identifies the jar file to be listed or extracted.
v
Generates verbose output on stderr.
m
Includes manifest information from specified pre-existing manifest file.
Example use:
jar cmf myManifestFile myJarFile *.class
You can add special-purpose name-value attribute headers to the manifest
file that aren't contained in the default manifest. Examples of such headers
would be those for vendor information, version information, package sealing,
and headers to make JAR-bundled applications executable. See the JAR
Files trail in the Java Tutorial and the JRE
Notes for Developers web page for examples of using the m
option.
0
Store only, without using ZIP compression.
M
Do not create a manifest file for the entries.
u
Update an existing JAR file by adding files or changing the manifest.
For example,
jar uf foo.jar foo.class
would add the file foo.class to the existing JAR file foo.jar,
and
jar umf manifest foo.jar
would update foo.jar's manifest with the information in manifest.
-C
Temporaily changes directories during execution of jar command
while processing the next argument. For example,
jar uf foo.jar -C classes bar.class
would change to the classes directory and add the bar.class
from that directory to foo.jar. The following command,
jar uf foo.jar -C classes . -C bin xyz.class
would change to the classes directory and add to foo.jar all f
iles within the classes directory, but not the
classes directory itself, and then change to the bin directory
and add xyz.class to foo.jar.
If any of "files" is a directory, then that directory is processed recursively.