Manual Pages for UNIX Darwin command on man jar
MyWebUniversity

Manual Pages for UNIX Darwin command on man jar

jar(1) jar(1)

NAME

jar - Java archive tool

SYNOPSIS

Create jar file

jjaarr cc[[vv00MM]]ff jarfile [ -CC dir ] inputfiles [ -JJoption ]

jjaarr cc[[vv00]]mmff manifest jarfile [ -CC dir ] inputfiles [ -JJoption ]

jjaarr cc[[vv00MM]] [ -CC dir ] inputfiles [ -JJoption ]

jjaarr cc[[vv00]]mm manifest [ -CC dir ] inputfiles [ -JJoption ]

Update jar file

jjaarr uu[[vv00MM]]ff jarfile [ -CC dir ] inputfiles [ -JJoption ]

jjaarr uu[[vv00]]mmff manifest jarfile [ -CC dir ] inputfiles [ -JJoption ]

jjaarr uu[[vv00MM]] [ -CC dir ] inputfiles [ -JJoption ]

jjaarr uu[[vv00]]mm manifest [ -CC dir ] inputfiles [ -JJoption ]

Extract jar file

jjaarr xx[[vv]]ff jarfile [ inputfiles ] [ -JJoption ]

jjaarr xx[[vv]] [ inputfiles ] [ -JJoption ]

List table of contents of jar file

jjaarr tt[[vv]]ff jarfile [ inputfiles ] [ -JJoption ]

jjaarr tt[[vv]] [ inputfiles ] [ -JJoption ]

Add index to jar file

jjaarr ii jarfile [ -JJoption ]

PPAARRAAMMEETTEERRSS

ccuuxxttiivvOOMMmmff Options that control the jar command.

jjaarrffiillee Jar file to be created (c), updated (u), extracted (x), or have its table of contents viewed (t). The f option

and filename jarfile are a pair - if either is present,

they must both appear. Note that omitting f and jarfile

accepts a "jar file" from standard input (for x and t)

or sends the "jar file" to standard output (for c and

u).

iinnppuuttffiilleess Files or directories, separated by spaces, to be com-

bined into jarfile (for c and u), or to be extracted

(for x) or listed (for t) from jarfile. All directories

are processed recursively. The files are compressed unless option O (zero) is used.

mmaanniiffeesstt Pre-existing manifest file whose name: value pairs are

to be included in MANIFEST.MF in the jar file. The m

option and filename manifest are a pair - if either is

present, they must both appear. The letters m and f must

appear in the same order that manifest and jarfile

appear.

-CC dir Temporarily changes directories to dir while processing

the following inputfiles argument. Multiple -CC dir

inputfiles sets are allowed.

-JJoption Option to be passed into the Java runtime environment.

(There must be no space between -J and option).

DESCRIPTION

The jjaarr tool 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, jjaarr 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 can

be downloaded by a Java agent (like a browser) in a single HTTP trans-

action, rather than require a new connection for each piece. This dra-

matically improves download time. The jjaarr tool also compresses files,

which further improves download time. In addition, it allows individ-

ual entries in a file to be signed by the applet author so that their origins can be authenticated. The syntax for the jjaarr tool is almost identical to the syntax for the ttaarr(1) command. A jjaarr archive can be used as a class path entry, whether or not it is compressed.

Typical usage to combine files into a jar file is:

%% jjaarr ccff mmyyFFiillee..jjaarr **..ccllaassss

In this example, all the class files in the current directory are

placed in the file named mmyyjjaarrffiillee. A manifest file entry named META-

INF/MANIFEST.MF is automatically generated by the jar tool and is

always the first entry in the jar file. The manifest file is the place

where any meta-information about the archive is stored as name:value

pairs. Refer to the Jar File specification for details about how meta-

information is stored in the manifest file.

If you have a pre-existing manifest file whose name: value pairs you

want the jar tool to include for the new jar archive, you can specify

it using the m option:

%% jjaarr ccmmff mmyyMMaanniiffeessttFFiillee mmyyJJaarrFFiillee **..ccllaassss

Be sure that any pre-existing manifest file that you use ends with a

new line. The last line of a manifest file will not be parsed if it doesn't end with a new line character. 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, fol-

lowed by the name of the manifest file:

%% jjaarr ccffmm mmyyJJaarrFFiillee mmyyMMaanniiffeessttFFiillee **..ccllaassss

The manifest is in a text format inspired by RFC822 ASCII format, so it

is easy to view and process manifest-file contents.

To extract the files from a jar file, use x , as in:

% jar xf myFile.jar

To extract only certain files from a jar file, supply their filenames:

% jar xf myFile.jar foo bar

Beginning with version 1.3 of the Java 2 SDK, the jar utility supports

JarIndex, 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 jar with the i option. It will generate package location infor-

mation for the specified main jar file and all the jar files it depends

on, which need to be specified in the Class-Path attribute of the main

jar file's manifest.

% jar i main.jar

In this example, an INDEX.LIST file is inserted into the META-INF

directory of main.jar. The application class loader will use the

information stored in this file for efficient class loading. Refer to the JarIndex specification for details about how location information is stored in the index file. A standard way to copy directories is to first compress files in dir1 to standard out, then extract from standard in to dir2 (omitting f from

both jar commands):

% (cd dir1; jar c .) | (cd dir2; jar x)

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

cc Creates a new archive file named jarfile (if f is specified) or to

standard output (if f and jarfile are omitted). Add to it the

files and directories specified by inputfiles.

uu Updates an existing file jarfile (when f is specified) by adding

to it files and directories specified by inputfiles. For example:

jar uf foo.jar foo.class

would add the file foo.class to the existing jar file foo.jar. The u

option can also update the manifest entry, as given by this example:

jar umf manifest foo.jar

updates the foo.jar manifest with the name: value pairs in manifest.

xx Extracts files and directories from jarfile (if f is specified) or

standard input (if f and jarfile are omitted). If inputfiles is

specified, only those specified files and directories are extracted. Otherwise, all files and directories are extracted.

tt Lists the table of contents from jarfile (if f is specified) or

standard input (if f and jarfile are omitted). If inputfiles is

specified, only those specified files and directories are listed. Otherwise, all files and directories are listed.

ii Generate index information for the specified jarfile and its

dependent jar files. For example:

jar i foo.jar

would generate an INDEX.LIST file in foo.jar which contains location

information for each package in foo.jar and all the jar files specified

in the Class-Path attribute of foo.jar. See the index example.

ff Specifies the file jarfile to be created (c), updated (u),

extracted (x), indexed (i), or viewed (t). The f option and file-

name jarfile are a pair - if present, they must both appear.

Omitting f and jarfile accepts a "jar file" from standard input

(for x and t) or sends the "jar file" to standard output (for c

and u). vv Generates verbose output to standard output. Examples shown below. 00 Zero. Store without using ZIP compression. MM Do not create a manifest file entry (for c and u), or delete a manifest file entry if one exists (for u). mm Includes name: value attribute pairs from the specified manifest

file manifest in the file at META-INF/MANIFEST.MF. A name: value

pair is added unless one already exists with the same name, in which case its value is updated. On the command line, the letters m and f must appear in the same order

that manifest and jarfile appear. Example use:

jar cmf myManifestFile myFile.jar *.class

You can add special-purpose name: value attribute pairs to the manifest

that aren't contained in the default manifest. Examples of such attributes would be those for vendor information, version information,

package sealing, and to make JAR-bundled applications executable. See

the JAR Files trail in the Java Tutorial and the Notes for Developers page for examples of using the m option.

-CC Temporarily changes directories (cd dir) during execution of the

jar command while processing the following inputfiles argument.

Its operation is intended to be similar to the -CC option of the

UNIX tar utility. For example:

%% jjaarr uuff ffoooo..jjaarr -CC ccllaasssseess bbaarr..ccllaasssseess

would change to the classes directory and add the bar.class from that

directory to foo.jar. The following command,

jjaarr uuff ffoooo..jjaarr -CC ccllaasssseess .. -CC bbiinn xxyyzz..ccllaassss

would change to the classes directory and add to foo.jar all files

within the classes directory (without creating a classes directory in

the jar file), then change back to the original directory before chang-

ing to the bin directory to add xyz.class to foo.jar. If classes holds

files bar1 and bar2, then here's what the jar file would contain using

jar tf foo.jar:

MMEETTAA-IINNFF//

MMEETTAA-IINNFF//MMAANNIIFFEESSTT..MMFF

bbaarr11 bbaarr22 xxyyzz..ccllaassss JJoption Pass option to the Java runtime environment, where option is one of the options described on the man page for the jjaavvaa application

launcher, jjaavvaa(1). For example, -JJ-XXmmss4488mm sets the startup memory

to 48 megabytes. It is a common convention for -JJ to pass options

to the underlying virtual machine. COMMAND LINE ARGUMENT FILES

To shorten or simplify the jar command line, you can specify one or

more files that themselves contain arguments to the jar command (except

-JJ options). This enables you to create jar commands of any length,

overcoming command line limits imposed by the operating system. 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 the location of the argument file. Wildcards (*) that might otherwise be expanded by the operating system shell are not expanded. Use of the '@'

character to recursively interpret files is not supported. The -J

options are not supported because they are passed to the launcher, which does not support argument files.

When executing jar, pass in the path and name of each argument file

with the '@' leading character. When jar encounters an argument begin-

ning with the character `@', it expands the contents of that file into the argument list. For example, you could use a single argument file named "classes.list" to hold the names of the files:

% find . -name '*.class' -print > classes.list

Then execute the jar command passing in the argfile:

% jar cf my.jar @classes.list

An argument file can be passed in with a path, but any filenames inside the argument file that have relative paths are relative to the current working directory, not the path passed in. Here's such an example:

% jar @path1/classes.list

EEXXAAMMPPLLEESS

To add all the files in a particular directory to an archive (overwrit-

ing contents if the archive already exists). Enumerating verbosely (with the "v" option) will tell you more information about the files in the archive, such as their size and last modified date.

%% llss

11..aauu AAnniimmaattoorr..ccllaassss mmoonnkkeeyy..jjppgg 22..aauu WWaavvee..ccllaassss ssppaacceemmuussiicc..aauu 33..aauu aattwwoorrkk..ggiiff

%% jjaarr ccvvff bbuunnddllee..jjaarr **

aaddddeedd mmaanniiffeesstt

aaddddiinngg:: 11..aauu((iinn == 22332244)) ((oouutt== 6677))((ddeeffllaatteedd 9977%%))

aaddddiinngg:: 22..aauu((iinn == 66997700)) ((oouutt== 9900))((ddeeffllaatteedd 9988%%))

aaddddiinngg:: 33..aauu((iinn == 1111661166)) ((oouutt== 110088))((ddeeffllaatteedd 9999%%))

aaddddiinngg:: AAnniimmaattoorr..ccllaassss((iinn == 22226666)) ((oouutt== 6666))((ddeeffllaatteedd 9977%%))

aaddddiinngg:: WWaavvee..ccllaassss((iinn == 33777788)) ((oouutt== 8811))((ddeeffllaatteedd 9977%%))

aaddddiinngg:: aattwwoorrkk..ggiiff((iinn == 66662211)) ((oouutt== 8899))((ddeeffllaatteedd 9988%%))

aaddddiinngg:: mmoonnkkeeyy..jjppgg((iinn == 77666677)) ((oouutt== 9911))((ddeeffllaatteedd 9988%%))

aaddddiinngg:: ssppaacceemmuussiicc..aauu((iinn == 33007799)) ((oouutt== 7733))((ddeeffllaatteedd 9977%%))

If you already have separate subdirectories for images, audio files and

classes, you can combine them into a single jar file:

%% llss -FF

aauuddiioo// ccllaasssseess// iimmaaggeess//

%% jjaarr ccvvff bbuunnddllee..jjaarr aauuddiioo ccllaasssseess iimmaaggeess

aaddddeedd mmaanniiffeesstt

aaddddiinngg:: aauuddiioo//((iinn == 00)) ((oouutt== 00))((ssttoorreedd 00%%))

aaddddiinngg:: aauuddiioo//11..aauu((iinn == 22332244)) ((oouutt== 6677))((ddeeffllaatteedd 9977%%))

aaddddiinngg:: aauuddiioo//22..aauu((iinn == 66997700)) ((oouutt== 9900))((ddeeffllaatteedd 9988%%))

aaddddiinngg:: aauuddiioo//33..aauu((iinn == 1111661166)) ((oouutt== 110088))((ddeeffllaatteedd 9999%%))

aaddddiinngg:: aauuddiioo//ssppaacceemmuussiicc..aauu((iinn == 33007799)) ((oouutt== 7733))((ddeeffllaatteedd 9977%%))

aaddddiinngg:: ccllaasssseess//((iinn == 00)) ((oouutt== 00))((ssttoorreedd 00%%))

aaddddiinngg:: ccllaasssseess//AAnniimmaattoorr..ccllaassss((iinn == 22226666)) ((oouutt== 6666))((ddeeffllaatteedd 9977%%))

aaddddiinngg:: ccllaasssseess//WWaavvee..ccllaassss((iinn == 33777788)) ((oouutt== 8811))((ddeeffllaatteedd 9977%%))

aaddddiinngg:: iimmaaggeess//((iinn == 00)) ((oouutt== 00))((ssttoorreedd 00%%))

aaddddiinngg:: iimmaaggeess//mmoonnkkeeyy..jjppgg((iinn == 77666677)) ((oouutt== 9911))((ddeeffllaatteedd 9988%%))

aaddddiinngg:: iimmaaggeess//aattwwoorrkk..ggiiff((iinn == 66662211)) ((oouutt== 8899))((ddeeffllaatteedd 9988%%))

%% llss -FF

aauuddiioo// bbuunnddllee..jjaarr ccllaasssseess// iimmaaggeess//

To see the entry names in the jarfile, use the tt option:

%% jjaarr ttff bbuunnddllee..jjaarr

MMEETTAA-IINNFF//

MMEETTAA-IINNFF//MMAANNIIFFEESSTT..MMFF

aauuddiioo//11..aauu aauuddiioo//22..aauu aauuddiioo//33..aauu aauuddiioo//ssppaacceemmuussiicc..aauu ccllaasssseess//AAnniimmaattoorr..ccllaassss ccllaasssseess//WWaavvee..ccllaassss iimmaaggeess//mmoonnkkeeyy..jjppgg iimmaaggeess//aattwwoorrkk..ggiiff

To add an index file to the jar file for speeding up class loading, use

the "i" option.

Let's say you split the inter-dependent classes for a stock trade

application, into three jar files: main.jar, buy.jar, and sell.jar. If

you specify the Class-path attribute in the main.jar manifest as:

Class-Path: buy.jar sell.jar

then you can use the i option to speed up your application's class loading time:

% jar i main.jar

An INDEX.LIST file is inserted to the META-INF directory which will

enable the application class loader to download the specified jar files

when it is searching for classes or resources.

SEE ALSO

The JAR Overview @

http://java.sun.com/javase/6/docs/technotes/guides/jar/jarGuide.html

The JAR File Specification @

http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html

The JARIndex Spec @

http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html

JAR Tutorial @

http://java.sun.com/docs/books/tutorial/jar/

pack200 Reference Page @ http://java.sun.com/javase/6/docs/technotes/tools/share/pack200.html

22 Jun 2004 jar(1)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™