jar-The Java Archive Tool

Combines multiple files into a single JAR archive file.

SYNOPSIS

 
I placed my JAR in Tennessee
On a high remote hill...
Where people can see its Java steam
That shapes their dreams and will...

.. from a Webmaster's diary...
found by Jeff Zhuk, Java Instructor

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.

The 3 types of input files for the jar tool are

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.INF. 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

When files are added to a jar archive, the file and its MD5 and SHA hashes are stored. The hashes are entered into the manifest file. It is easy to view and process the contents of the manifest file, since it uses RFC822 ascii format.

OPTIONS

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 extract, the second argument identifies the jar file to be listed or extracted.

v
Generates verbose output on stderr.

If any of "files" is a directory, then that directory is processed recursively.
Usage on a Web page:

    < applet archive="itschool.jar" code="MainJava.class" width=80 hight=50>
    < param name="FirstName" value="Jeff">
    .....
    < /applet>

SEE also documents from JDK/DOCS/GUIDE/JAR

Back to Java School