jdk/src/linux/doc/man/jar.1
author mikejwre
Wed, 09 Jun 2010 18:56:41 -0700
changeset 5634 895b66935810
parent 5506 202f599c92aa
child 5865 47da38a8c0f0
permissions -rw-r--r--
Merge

." Copyright 2004-2006 Sun Microsystems, Inc.  All Rights Reserved.
." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
."
." This code is free software; you can redistribute it and/or modify it
." under the terms of the GNU General Public License version 2 only, as
." published by the Free Software Foundation.
."
." This code is distributed in the hope that it will be useful, but WITHOUT
." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
." version 2 for more details (a copy is included in the LICENSE file that
." accompanied this code).
."
." You should have received a copy of the GNU General Public License version
." 2 along with this work; if not, write to the Free Software Foundation,
." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
."
." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
." or visit www.oracle.com if you need additional information or have any
." questions.
."
.TH jar 1 "04 May 2009"
." Generated from HTML by html2man (author: Eric Armstrong)

.LP
.SH "Name"
jar\-The Java Archive Tool
.LP
\f3jar\fP combines multiple files into a single JAR archive file.   
.SH "SYNOPSIS"
.LP

.LP
.RS 3
.TP 3
Create jar file 
\f4jar c\fP\f2[v0Mmfe] [\fP\f2manifest\fP\f2] [\fP\f2jarfile\fP\f2] [\fP\f2entrypoint\fP\f2] [\-C\fP \f2dir\fP\f2]\fP \f2inputfiles\fP \f2[\-J\fP\f2option\fP\f2]\fP 
.TP 3
Update jar file 
\f4jar u\fP\f2[v0Mmfe] [\fP\f2manifest\fP\f2] [\fP\f2jarfile\fP\f2] [\fP\f2entrypoint\fP\f2] [\-C\fP \f2dir\fP\f2]\fP \f2inputfiles\fP \f2[\-J\fP\f2option\fP\f2]\fP 
.TP 3
Extract jar file 
\f4jar x\fP\f2[vf] [\fP\f2jarfile\fP\f2] [\fP\f2inputfiles\fP\f2] [\-J\fP\f2option\fP\f2]\fP 
.TP 3
List table of contents of jar file 
\f4jar t\fP\f2[vf] [\fP\f2jarfile\fP\f2] [\fP\f2inputfiles\fP\f2] [\-J\fP\f2option\fP\f2]\fP 
.TP 3
Add index to jar file 
\f4jar i\fP \f2jarfile\fP \f2[\-J\fP\f2option\fP\f2]\fP 
.RE

.LP
.LP
where:
.LP
.RS 3

.LP
.RS 3
.TP 3
cuxtiv0Mmfe 
Options that control the \f2jar\fP command. 
.TP 3
jarfile 
Jar file to be created (\f2c\fP), updated (\f2u\fP), extracted (\f2x\fP), or have its table of contents viewed (\f2t\fP). The \f2\-f\fP option and filename \f2jarfile\fP are a pair \-\- if either is present, they must both appear. Note that omitting \f2f\fP and \f2jarfile\fP accepts a "jar file" from standard input (for x and t) or sends the "jar file" to standard output (for c and u). 
.TP 3
inputfiles 
Files or directories, separated by spaces, to be combined into \f2jarfile\fP (for c and u), or to be extracted (for x) or listed (for t) from \f2jarfile\fP. All directories are processed recursively. The files are compressed unless option \f20\fP (zero) is used. 
.TP 3
manifest 
Pre\-existing manifest file whose \f2name\fP\f2:\fP \f2value\fP pairs are to be included in MANIFEST.MF in the jar file. The \f2\-m\fP option and filename \f2manifest\fP are a pair \-\- if either is present, they must both appear. The letters \f3m\fP, \f3f\fP and \f3e\fP must appear in the same order that \f2manifest\fP, \f2jarfile\fP, \f2entrypoint\fP appear. 
.TP 3
entrypoint 
The name of the class that set as the application entry point for stand\-alone applications bundled into executable jar file. The \f2\-e\fP option and entrypoint are a pair \-\- if either is present, they must both appear. The letters \f3m\fP, \f3f\fP and \f3e\fP must appear in the same order that \f2manifest\fP, \f2jarfile\fP, \f2entrypoint\fP appear. 
.TP 3
\-C\ dir 
Temporarily changes directories to \f2dir\fP while processing the following \f2inputfiles\fP argument. Multiple \f2\-C\ \fP\f2dir\fP \f2inputfiles\fP sets are allowed. 
.TP 3
\-Joption 
Option to be passed into the Java runtime environment. (There must be no space between \f2\-J\fP and \f2option\fP). 
.RE

.LP
.RE
.SH "DESCRIPTION"
.LP

.LP
The \f3jar\fP tool combines multiple files into a single JAR archive file. \f3jar\fP is a general\-purpose archiving and compression tool, based on ZIP and the 
.na
\f2ZLIB\fP @
.fi
http://www.gzip.org/zlib/ compression format. However, \f3jar\fP was designed mainly package java applets or applications into a single archive. When the components of an applet or application (files, images and sounds) are combined into a single archive, they can 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. \f3jar\fP 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 \f2tar\fP command. A \f3jar\fP archive can be used as a class path entry, whether or not it is compressed. 
.LP
Typical usage to combine files into a jar file is:
.LP
.RS 3

.LP
.nf
\f3
.fl
% jar cf myFile.jar *.class
.fl
\fP
.fi
.RE

.LP
In this example, all the class files in the current directory are placed into the file named \f2myFile.jar\fP. The jar tool automatically generates a manifest file entry named \f2META\-INF/MANIFEST.MF\fP. It is always the first entry in the jar file. The manifest file declares meta\-information about the archive, and stores that data as \f2name\ :\ value\fP pairs. Refer to the 
.na
\f2JAR file specification\fP @
.fi
http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest for details explaining how the jar tool stores meta\-information in the manifest file. 
.LP
If a jar file should include \f2name\ :\ value\fP pairs contained in an existing manifest file, specify that file using the \f2\-m\fP option:
.LP
.RS 3

.LP
.nf
\f3
.fl
% jar cmf myManifestFile myFile.jar *.class
.fl
\fP
.fi
.RE

.LP
An existing manifest file must end with a new line character.\  \f3jar\fP does not parse the last line of a manifest file if it does not end with a new line character.
.br

.LP
.br

.LP
\f3Note:\ \fP A jar command that specifies \f2cfm\fP on the command line instead of \f2cmf\fP (the order of the m and \-f options are reversed), the \f3jar\fP command line must specify the name of the jar archive first, followed by the name of the manifest file: 
.RS 3

.LP
.nf
\f3
.fl
% jar cfm myFile.jar myManifestFile *.class
.fl
\fP
.fi
.RE

.LP
The manifest is in a text format inspired by RFC822 ASCII format, so it is easy to view and process manifest\-file contents. 
.LP
To extract the files from a jar file, use \f2x\fP:
.LP
.RS 3

.LP
.nf
\f3
.fl
% jar xf myFile.jar
.fl
\fP
.fi
.RE

.LP
.LP
To extract individual files from a jar file, supply their filenames:
.LP
.RS 3

.LP
.nf
\f3
.fl
% jar xf myFile.jar foo bar
.fl
\fP
.fi
.RE

.LP
.LP
Beginning with version 1.3 of the Java 2 SDK, the \f2jar\fP utility supports 
.na
\f2JarIndex\fP @
.fi
http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Index, which allows application class loaders to load classes more efficiently from jar files. If an application or applet is bundled into multiple jar files,\  only the necessary jar files will be downloaded and opened to load classes. This performance optimization is enabled by running \f2jar\fP with the \f2\-i\fPoption. It will generate package location information for the specified main jar file and all the jar files it depends on, which need to be specified in the \f2Class\-Path\fP attribute of the main jar file's manifest.
.LP
.RS 3

.LP
.nf
\f3
.fl
% jar i main.jar
.fl
\fP
.fi
.RE

.LP
.LP
In this example, an \f2INDEX.LIST\fP file is inserted into the \f2META\-INF\fP directory of \f2main.jar\fP.
.br
.br
The application class loader uses the information stored in this file for efficient class loading.\  For details about how location information is stored in the index file, refer to the \f2JarIndex\fP specification.
.br
.br
To copy directories, first compress files in \f2dir1\fP to \f2stdout\fP, then extract from \f2stdin\fP to \f2dir2\fP (omitting the \f2\-f\fP option from both \f2jar\fP commands):
.LP
.RS 3

.LP
.nf
\f3
.fl
% (cd dir1; jar c .) | (cd dir2; jar x)
.fl
\fP
.fi
.RE

.LP
.LP
To review command samples which use \f2jar\fP to opeate on jar files and jar file manifests, see Examples, below. Also refer to the jar trail of the 
.na
\f2Java Tutorial\fP @
.fi
http://java.sun.com/docs/books/tutorial/jar.
.LP
.SH "OPTIONS"
.LP

.LP
.RS 3
.TP 3
c 
Creates a new archive file named \f2jarfile\fP (if \f2f\fP is specified) or to standard output (if \f2f\fP and \f2jarfile\fP are omitted). Add to it the files and directories specified by \f2inputfiles\fP. 
.TP 3
u 
Updates an existing file \f2jarfile\fP (when \f2f\fP is specified) by adding to it files and directories specified by \f2inputfiles\fP. For example: 
.RS 3

.LP
.nf
\f3
.fl
jar uf foo.jar foo.class
.fl
\fP
.fi
.RE
would add the file \f2foo.class\fP to the existing jar file \f2foo.jar\fP. The \f2\-u\fP option can also update the manifest entry, as given by this example: 
.RS 3

.LP
.nf
\f3
.fl
jar umf manifest foo.jar
.fl
\fP
.fi
.RE
updates the \f2foo.jar\fP manifest with the \f2name : value\fP pairs in \f2manifest\fP. 
.TP 3
x 
Extracts files and directories from \f2jarfile\fP (if \f2f\fP is specified) or standard input (if \f2f\fP and \f2jarfile\fP are omitted). If \f2inputfiles\fP is specified, only those specified files and directories are extracted. Otherwise, all files and directories are extracted. The time and date of the extracted files are those given in the archive. 
.TP 3
t 
Lists the table of contents from \f2jarfile\fP (if \f2f\fP is specified) or standard input (if \f2f\fP and \f2jarfile\fP are omitted). If \f2inputfiles\fP is specified, only those specified files and directories are listed. Otherwise, all files and directories are listed. 
.TP 3
i 
Generate index information for the specified \f2jarfile\fP and its dependent jar files. For example: 
.RS 3

.LP
.nf
\f3
.fl
jar i foo.jar
.fl
\fP
.fi
.RE
.LP
would generate an \f2INDEX.LIST\fP file in \f2foo.jar\fP which contains location information for each package in \f2foo.jar\fP and all the jar files specified in the \f2Class\-Path\fP attribute of \f2foo.jar\fP. See the index example.   
.TP 3
f 
Specifies the file \f2jarfile\fP to be created (\f2c\fP), updated (\f2u\fP), extracted (\f2x\fP), indexed (\f2i\fP), or viewed (\f2t\fP). The \f2\-f\fP option and filename \f2jarfile\fP are a pair \-\- if present, they must both appear. Omitting \f2f\fP and \f2jarfile\fP accepts a jar file name from \f2stdin\fP(for x and t) or sends jar file to \f2stdout\fP (for c and u). 
.TP 3
v 
Generates verbose output to standard output. Examples shown below. 
.TP 3
0 
(zero) Store without using ZIP compression. 
.TP 3
M 
Do not create a manifest file entry (for c and u), or delete a manifest file entry if one exists (for u). 
.TP 3
m 
Includes \f2name : value\fP attribute pairs from the specified manifest file \f2manifest\fP in the file at \f2META\-INF/MANIFEST.MF\fP. \f2jar\fP adds a \f2name\ :\ value\fP pair unless an entry already exists with the same name, in which case \f2jar\fP updates its value. 
.LP
On the command line, the letters \f3m\fP and \f3f\fP must appear in the same order that \f2manifest\fP and \f2jarfile\fP appear. Example use: 
.RS 3

.LP
.nf
\f3
.fl
jar cmf myManifestFile myFile.jar *.class
.fl
\fP
.fi
.RE
You can add special\-purpose \f2name\ :\ value\fP attribute pairs to the manifest that aren't contained in the default manifest. For example, you can add attributes specifying vendor information, version information, package sealing, or to make JAR\-bundled applications executable. See the 
.na
\f2JAR Files\fP @
.fi
http://java.sun.com/docs/books/tutorial/jar/ trail in the Java Tutorial  for examples of using the \f4\-m\fP option. 
.LP
.TP 3
e 
Sets \f2entrypoint\fP as the application entry point for stand\-alone applications bundled into executable jar file. The use of this option creates or overrides the \f2Main\-Class\fP attribute value in the manifest file. This option can be used during creation of jar file or while updating the jar file. This option specifies the application entry point without editing or creating the manifest file.
.br
.br
For example, this command creates \f2Main.jar\fP where the \f2Main\-Class\fP attribute value in the manifest is set to \f2Main\fP: 
.RS 3

.LP
.nf
\f3
.fl
jar cfe Main.jar Main Main.class
.fl
\fP
.fi
.RE
.LP
The java runtime can directly invoke this application by running the following command: 
.RS 3

.LP
.nf
\f3
.fl
java \-jar Main.jar
.fl
\fP
.fi
.RE
If the entrypoint class name is in a package it may use either a dot (".") or slash ("/") character as the delimiter. For example, if \f2Main.class\fP is in a package called \f2foo\fP the entry point can be specified in the following ways: 
.RS 3

.LP
.nf
\f3
.fl
jar \-cfe Main.jar foo/Main foo/Main.class
.fl
\fP
.fi
.RE
or 
.RS 3

.LP
.nf
\f3
.fl
jar \-cfe Main.jar foo.Main foo/Main.class
.fl
\fP
.fi
.RE
\f3Note:\ \fP specifying both \f2\-m\fP and \f2\-e\fP options together when the given manifest also contains the \f2Main\-Class\fP attribute results in an ambigous \f2Main.class\fP specification, leading to an error and the jar creation or update operation is aborted. 
.LP
.TP 3
\-C \ dir 
Temporarily changes directories (\f2cd\fP\ \f2dir\fP) during execution of the \f2jar\fP command while processing the following \f2inputfiles\fP argument. Its operation is intended to be similar to the \f2\-C\fP option of the UNIX \f2tar\fP utility.
.br
.br
For example, this command changes to the \f2classes\fP directory and adds the \f2bar.class\fP from that directory to \f2foo.jar\fP: 
.RS 3

.LP
.nf
\f3
.fl
jar uf foo.jar \-C classes bar.class
.fl
\fP
.fi
.RE
This command changes to the \f2classes\fP directory and adds to \f2foo.jar\fP all files within the \f2classes\fP directory (without creating a classes directory in the jar file), then changes back to the original directory before changing to the \f2bin\fP directory to add \f2xyz.class\fP to \f2foo.jar\fP. 
.RS 3

.LP
.nf
\f3
.fl
jar uf foo.jar \-C classes . \-C bin xyz.class
.fl
\fP
.fi
.RE
If \f2classes\fP holds files \f2bar1\fP and \f2bar2\fP, then here's what the jar file will contain using \f2jar tf foo.jar\fP: 
.RS 3

.LP
.nf
\f3
.fl
META\-INF/
.fl
META\-INF/MANIFEST.MF
.fl
bar1
.fl
bar2
.fl
xyz.class
.fl
\fP
.fi
.RE
.LP
.TP 3
\-Joption 
Pass \f2option\fP to the Java runtime environment, where \f2option\fP is one of the options described on the reference page for the java application launcher. For example, \f4\-J\-Xmx48M\fP sets the maximum memory to 48 megabytes. It is a common convention for \f2\-J\fP to pass options to the underlying runtime environment. 
.RE

.LP
.SH "COMMAND LINE ARGUMENT FILES"
.LP

.LP
To shorten or simplify the jar command line, you can specify one or more files that themselves contain arguments to the \f2jar\fP command (except \f2\-J\fP options). This enables you to create jar commands of any length, overcoming command line limits imposed by the operating system. 
.LP
An argument file can include options and filenames. The arguments within a file can be space\-separated or newline\-separated. Filenames within an argument file are relative to the current directory, not relative to the location of the argument file. Wildcards (*) that might otherwise be expanded by the operating system shell are not expanded. Use of the \f2@\fP character to recursively interpret files is not supported. The \f2\-J\fP options are not supported because they are passed to the launcher, which does not support argument files.
.LP
.LP
When executing \f2jar\fP, pass in the path and name of each argument file with the \f2@\fP leading character. When \f2jar\fP encounters an argument beginning with the character \f2@\fP, it expands the contents of that file into the argument list.
.br
.br
The example below, \f2classes.list\fP holds the names of files output by a \f2find\fP command: 
.LP
.RS 3

.LP
.nf
\f3
.fl
% find \fP\f3.\fP \-name '*.class' \-print > classes.list
.fl
.fi
.RE

.LP
.LP
You can then execute the \f2jar\fP command on \f2Classes.list\fP by passing it to \f2jar\fP using argfile syntax:
.LP
.RS 3

.LP
.nf
\f3
.fl
% jar cf my.jar @classes.list
.fl
\fP
.fi
.RE

.LP
An argument file can specify a path, but any filenames inside the argument file that have relative paths are relative to the current working directory, not to the path passed in. Here is an example: 
.RS 3

.LP
.nf
\f3
.fl
% jar @path1/classes.list
.fl
\fP
.fi
.RE

.LP
.LP

.LP
.SH "EXAMPLES"
.LP

.LP
To add all the files in a particular directory to an archive (overwriting contents if the archive already exists). Enumerating verbosely (with the \f2\-v\fP option) will tell you more information about the files in the archive, such as their size and last modified date. 
.RS 3

.LP
.nf
\f3
.fl
% ls
.fl
1.au          Animator.class    monkey.jpg
.fl
2.au          Wave.class        spacemusic.au
.fl
3.au          at_work.gif
.fl

.fl
% jar cvf bundle.jar *
.fl
added manifest
.fl
adding: 1.au(in = 2324) (out= 67)(deflated 97%)
.fl
adding: 2.au(in = 6970) (out= 90)(deflated 98%)
.fl
adding: 3.au(in = 11616) (out= 108)(deflated 99%)
.fl
adding: Animator.class(in = 2266) (out= 66)(deflated 97%)
.fl
adding: Wave.class(in = 3778) (out= 81)(deflated 97%)
.fl
adding: at_work.gif(in = 6621) (out= 89)(deflated 98%)
.fl
adding: monkey.jpg(in = 7667) (out= 91)(deflated 98%)
.fl
adding: spacemusic.au(in = 3079) (out= 73)(deflated 97%)
.fl
\fP
.fi
.RE

.LP
If you already have separate subdirectories for images, audio files and classes, you can combine them into a single jar file: 
.RS 3

.LP
.nf
\f3
.fl
% ls \-F
.fl
audio/ classes/ images/
.fl

.fl
% jar cvf bundle.jar audio classes images
.fl
added manifest
.fl
adding: audio/(in = 0) (out= 0)(stored 0%)
.fl
adding: audio/1.au(in = 2324) (out= 67)(deflated 97%)
.fl
adding: audio/2.au(in = 6970) (out= 90)(deflated 98%)
.fl
adding: audio/3.au(in = 11616) (out= 108)(deflated 99%)
.fl
adding: audio/spacemusic.au(in = 3079) (out= 73)(deflated 97%)
.fl
adding: classes/(in = 0) (out= 0)(stored 0%)
.fl
adding: classes/Animator.class(in = 2266) (out= 66)(deflated 97%)
.fl
adding: classes/Wave.class(in = 3778) (out= 81)(deflated 97%)
.fl
adding: images/(in = 0) (out= 0)(stored 0%)
.fl
adding: images/monkey.jpg(in = 7667) (out= 91)(deflated 98%)
.fl
adding: images/at_work.gif(in = 6621) (out= 89)(deflated 98%)
.fl

.fl
% ls \-F
.fl
audio/ bundle.jar classes/ images/
.fl
\fP
.fi
.RE

.LP
To see the entry names in the jarfile, use the \f2t\fP option: 
.RS 3

.LP
.nf
\f3
.fl
% jar tf bundle.jar
.fl
META\-INF/
.fl
META\-INF/MANIFEST.MF
.fl
audio/1.au
.fl
audio/2.au
.fl
audio/3.au
.fl
audio/spacemusic.au
.fl
classes/Animator.class
.fl
classes/Wave.class
.fl
images/monkey.jpg
.fl
images/at_work.gif
.fl
\fP
.fi
.RE

.LP
.LP
To add an index file to the jar file for speeding up class loading, use the \f2i\fP option.
.br
.br
Example:
.br

.LP
.RS 3

.LP
If you split the inter\-dependent classes for a stock trade application into three jar files: \f2main.jar\fP, \f2buy.jar\fP, and \f2sell.jar\fP.
.br

.LP
.br

.LP
If you specify the \f2Class\-path\fP attribute in the \f2main.jar\fP manifest as: 
.nf
\f3
.fl
Class\-Path: buy.jar sell.jar
.fl
\fP
.fi

.LP
then you can use the \f2\-i\fP option to speed up the class loading time for your application: 
.nf
\f3
.fl
% jar i main.jar
.fl
\fP
.fi

.LP
An \f2INDEX.LIST\fP file is inserted to the \f2META\-INF\fP directory. This enables the application class loader to download the specified jar files when it is searching for classes or resources.
.RE
.SH "SEE ALSO"
.LP

.LP
.na
\f2The Jar Overview\fP @
.fi
http://java.sun.com/javase/6/docs/technotes/guides/jar/jarGuide.html
.br

.LP
.na
\f2The Jar File Specification\fP @
.fi
http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html
.br

.LP
.na
\f2The JarIndex Spec\fP @
.fi
http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Index
.br

.LP
.na
\f2Jar Tutorial\fP @
.fi
http://java.sun.com/docs/books/tutorial/jar on the Java Software web site.
.br

.LP
pack200(1) 
.LP