1jar(1)                      General Commands Manual                     jar(1)
2
3
4

NAME

6       jar-The Java Archive Tool
7
8       jar combines multiple files into a single JAR archive file.
9

SYNOPSIS

11       Create jar file
12          jar  c[v0Mmfe] [manifest] [jarfile] [entrypoint] [-C dir] inputfiles
13          [-Joption]
14
15       Update jar file
16          jar u[v0Mmfe] [manifest] [jarfile] [entrypoint] [-C dir]  inputfiles
17          [-Joption]
18
19       Extract jar file
20          jar x[vf] [jarfile] [inputfiles] [-Joption]
21
22       List table of contents of jar file
23          jar t[vf] [jarfile] [inputfiles] [-Joption]
24
25       Add index to jar file
26          jar i jarfile [-Joption]
27
28       where:
29
30          cuxtiv0Mmfe
31             Options that control the jar command.
32
33           jarfile
34             Jar  file  to be created (c), updated (u), extracted (x), or have
35             its table of contents viewed (t).  The  -f  option  and  filename
36             jarfile  are  a  pair  --  if  either  is present, they must both
37             appear. Note that omitting f and jarfile  accepts  a  "jar  file"
38             from  standard  input  (for  x  and t) or sends the "jar file" to
39             standard output (for c and u).
40
41
42          inputfiles
43             Files or directories, separated by spaces, to  be  combined  into
44             jarfile  (for c and u), or to be extracted (for x) or listed (for
45             t) from jarfile. All directories are processed  recursively.  The
46             files are compressed unless option 0 (zero) is used.
47
48           manifest
49             Pre-existing  manifest  file  whose  name:  value pairs are to be
50             included in MANIFEST.MF in the jar file. The -m option and  file‐
51             name  manifest are a pair -- if either is present, they must both
52             appear. The letters m, f and e must appear in the same order that
53             manifest, jarfile, entrypoint appear.
54
55
56          entrypoint
57             The name of the class that set as the application entry point for
58             stand-alone applications bundled into executable jar file. The -e
59             option  and  entrypoint  are a pair -- if either is present, they
60             must both appear. The letters m, f and e must appear in the  same
61             order that manifest, jarfile, entrypoint appear.
62
63          -C dir
64             Temporarily  changes directories to dir while processing the fol‐
65             lowing inputfiles argument. Multiple -C dir inputfiles  sets  are
66             allowed.
67
68          -Joption
69             Option  to  be  passed  into the Java runtime environment. (There
70             must be no space between -J and option).
71

DESCRIPTION

73       The jar tool combines multiple files into a single  JAR  archive  file.
74       jar  is  a general-purpose archiving and compression tool, based on ZIP
75       and the ZLIB @
76       http://www.gzip.org/zlib/ compression format. However, jar was designed
77       mainly package java applets or applications into a single archive. When
78       the components of an applet or application (files, images and sounds)
79       are combined into a single archive, they can be downloaded by a java
80       agent (like a browser) in a single HTTP transaction, rather than
81       requiring a new connection for each piece. This dramatically improves
82       download times. jar also compresses files and so further improves down‐
83       load time. In addition, it allows individual entries in a file to be
84       signed by the applet author so that their origin can be authenticated.
85       The syntax for the jar tool is almost identical to the syntax for the
86       tar command. A jar archive can be used as a class path @
87       http://ccc.sfbay/4291383/attachment/classpath.html entry, whether or
88       not it is compressed.
89
90       Typical usage to combine files into a jar file is:
91
92          % jar cf myFile.jar *.class
93
94
95       In this example, all the class files in the current directory are
96       placed into the file named myFile.jar. The jar tool automatically gen‐
97       erates a manifest file entry named META-INF/MANIFEST.MF. It is always
98       the first entry in the jar file. The manifest file declares meta-infor‐
99       mation about the archive, and stores that data as name : value pairs.
100       Refer to the JAR file specification @
101       http://ccc.sfbay/guide/jar/jar.html#JAR%20Manifest for details explain‐
102       ing how the jar tool stores meta-information in the manifest file.
103
104       If a jar file should include name : value pairs contained in an exist‐
105       ing manifest file, specify that file using the -m option:
106
107          % jar cmf myManifestFile myFile.jar *.class
108
109
110       An existing manifest file must end with a new line character.  jar does
111       not parse the last line of a manifest file if it does not end with a
112       new line character.
113
114
115       Note:  A jar command that specifies cfm on the command line instead of
116       cmf (the order of the m and -f options are reversed), the jar command
117       line must specify the name of the jar archive first, followed by the
118       name of the manifest file:
119
120
121          % jar cfm myFile.jar myManifestFile *.class
122
123
124       The manifest is in a text format inspired by RFC822 ASCII format, so it
125       is easy to view and process manifest-file contents.
126
127       To extract the files from a jar file, use x:
128
129          % jar xf myFile.jar
130
131
132       To extract individual files from a jar file, supply their filenames:
133
134          % jar xf myFile.jar foo bar
135
136
137       Beginning with version 1.3 of the Java 2 SDK, the jar utility supports
138       JarIndex @
139       http://ccc.sfbay/guide/jar/jar.html#JAR%20Index, which allows applica‐
140       tion class loaders to load classes more efficiently from jar files. If
141       an application or applet is bundled into multiple jar files,  only the
142       necessary jar files will be downloaded and opened to load classes. This
143       performance optimization is enabled by running jar with the -ioption.
144       It will generate package location information for the specified main
145       jar file and all the jar files it depends on, which need to be speci‐
146       fied in the Class-Path attribute of the main jar file's manifest.
147
148          % jar i main.jar
149
150
151       In this example, an INDEX.LIST file is inserted into the META-INF
152       directory of main.jar.
153       The application class loader uses the information stored in this file
154       for efficient class loading.  For details about how location informa‐
155       tion is stored in the index file, refer to the JarIndex specification.
156       To copy directories, first compress files in dir1 to stdout, then
157       extract from stdin to dir2 (omitting the -f option from both jar com‐
158       mands):
159
160          % (cd dir1; jar c .) | (cd dir2; jar x)
161
162
163       To review command samples which use jar to opeate on jar files and jar
164       file manifests, see Examples, below. Also refer to the jar trail of the
165       Java Tutorial @
166       http://java.sun.com/docs/books/tutorial/jar.
167

OPTIONS

169       c  Creates a new archive file named jarfile (if f is specified) or to
170          standard output (if f and jarfile are omitted). Add to it the files
171          and directories specified by inputfiles.
172
173       u  Updates an existing file jarfile (when f is specified) by adding to
174          it files and directories specified by inputfiles. For example:
175
176
177          jar uf foo.jar foo.class
178       would add the file foo.class to the existing jar file foo.jar. The -u
179       option can also update the manifest entry, as given by this example:
180
181
182          jar umf manifest foo.jar
183       updates the foo.jar manifest with the name : value pairs in manifest.
184
185       x  Extracts files and directories from jarfile (if f is specified) or
186          standard input (if f and jarfile are omitted). If inputfiles is
187          specified, only those specified files and directories are extracted.
188          Otherwise, all files and directories are extracted. The time and
189          date of the extracted files are those given in the archive.
190
191       t  Lists the table of contents from jarfile (if f is specified) or
192          standard input (if f and jarfile are omitted). If inputfiles is
193          specified, only those specified files and directories are listed.
194          Otherwise, all files and directories are listed.
195
196       i  Generate index information for the specified jarfile and its depen‐
197          dent jar files. For example:
198
199
200          jar i foo.jar
201
202       would generate an INDEX.LIST file in foo.jar which contains location
203       information for each package in foo.jar and all the jar files specified
204       in the Class-Path attribute of foo.jar. See the index example.
205
206       f  Specifies the file jarfile to be created (c), updated (u), extracted
207          (x), indexed (i), or viewed (t). The -f option and filename jarfile
208          are a pair -- if present, they must both appear. Omitting f and
209          jarfile accepts a jar file name from stdin(for x and t) or sends jar
210          file to stdout (for c and u).
211
212       v  Generates verbose output to standard output. Examples shown below.
213
214       0  (zero) Store without using ZIP compression.
215
216       M  Do not create a manifest file entry (for c and u), or delete a mani‐
217          fest file entry if one exists (for u).
218
219       m  Includes name : value attribute pairs from the specified manifest
220          file manifest in the file at META-INF/MANIFEST.MF. jar adds a
221          name : value pair unless an entry already exists with the same name,
222          in which case jar updates its value.
223
224       On the command line, the letters m and f must appear in the same order
225       that manifest and jarfile appear. Example use:
226
227
228          jar cmf myManifestFile myFile.jar *.class
229       You can add special-purpose name : value attribute pairs to the mani‐
230       fest that aren't contained in the default manifest. For example, you
231       can add attributes specifying vendor information, version information,
232       package sealing, or to make JAR-bundled applications executable. See
233       the JAR Files @
234       http://java.sun.com/docs/books/tutorial/jar/ trail in the Java Tutorial
235       for examples of using the -m option.
236
237       e  Sets entrypoint as the application entry point for stand-alone
238          applications bundled into executable jar file. The use of this
239          option creates or overrides the Main-Class attribute value in the
240          manifest file. This option can be used during creation of jar file
241          or while updating the jar file. This option specifies the applica‐
242          tion entry point without editing or creating the manifest file.
243          For example, this command creates Main.jar where the Main-Class
244          attribute value in the manifest is set to Main:
245
246
247          jar cfe Main.jar Main Main.class
248
249       The java runtime can directly invoke this application by running the
250       following command:
251
252
253          java -jar Main.jar
254       If the entrypoint class name is in a package it may use either a dot
255       (".") or slash ("/") character as the delimiter. For example, if
256       Main.class is in a package called foo the entry point can be specified
257       in the following ways:
258
259
260          jar -cfe Main.jar foo/Main foo/Main.class
261       or
262
263
264          jar -cfe Main.jar foo.Main foo/Main.class
265       Note:  specifying both -m and -e options together when the given mani‐
266       fest also contains the Main-Class attribute results in an ambigous
267       Main.class specification, leading to an error and the jar creation or
268       update operation is aborted.
269
270       -C  dir
271          Temporarily changes directories (cd dir) during execution of the jar
272          command while processing the following inputfiles argument. Its
273          operation is intended to be similar to the -C option of the UNIX tar
274          utility.
275          For example, this command changes to the classes directory and adds
276          the bar.class from that directory to foo.jar:
277
278
279          jar uf foo.jar -C classes bar.class
280       This command changes to the classes directory and adds to foo.jar all
281       files within the classes directory (without creating a classes direc‐
282       tory in the jar file), then changes back to the original directory
283       before changing to the bin directory to add xyz.class to foo.jar.
284
285
286          jar uf foo.jar -C classes . -C bin xyz.class
287       If classes holds files bar1 and bar2, then here's what the jar file
288       will contain using jar tf foo.jar:
289
290
291          META-INF/
292          META-INF/MANIFEST.MF
293          bar1
294          bar2
295          xyz.class
296
297       -Joption
298          Pass option to the Java runtime environment, where option is one of
299          the options described on the reference page for the java application
300          launcher @
301          http://ccc.sfbay/4291383/attachment/java.html#options. For example,
302          -J-Xmx48M sets the maximum memory to 48 megabytes. It is a common
303          convention for -J to pass options to the underlying runtime environ‐
304          ment.
305

COMMAND LINE ARGUMENT FILES

307       To shorten or simplify the jar command line, you can specify one or
308       more files that themselves contain arguments to the jar command (except
309       -J options). This enables you to create jar commands of any length,
310       overcoming command line limits imposed by the operating system.
311
312       An argument file can include options and filenames. The arguments
313       within a file can be space–separated or newline-separated. File‐
314       names within an argument file are relative to the current directory,
315       not relative to the location of the argument file. Wildcards (*) that
316       might otherwise be expanded by the operating system shell are not
317       expanded. Use of the @ character to recursively interpret files is not
318       supported. The -J options are not supported because they are passed to
319       the launcher, which does not support argument files.
320
321       When executing jar, pass in the path and name of each argument file
322       with the @ leading character. When jar encounters an argument beginning
323       with the character @, it expands the contents of that file into the
324       argument list.
325       The example below, classes.list holds the names of files output by a
326       find command:
327
328          % find . -name '*.class' -print > classes.list
329
330
331       You can then execute the jar command on Classes.list by passing it to
332       jar using argfile syntax:
333
334          % jar cf my.jar @classes.list
335
336
337       An argument file can specify a path, but any filenames inside the argu‐
338       ment file that have relative paths are relative to the current working
339       directory, not to the path passed in. Here is an example:
340
341
342          % jar @path1/classes.list
343
344

EXAMPLES

346       To add all the files in a particular directory to an archive (overwrit‐
347       ing contents if the archive already exists). Enumerating verbosely
348       (with the -v option) will tell you more information about the files in
349       the archive, such as their size and last modified date.
350
351
352          % ls
353          1.au          Animator.class    monkey.jpg
354          2.au          Wave.class        spacemusic.au
355          3.au          at_work.gif
356
357          % jar cvf bundle.jar *
358          added manifest
359          adding: 1.au(in = 2324) (out= 67)(deflated 97%)
360          adding: 2.au(in = 6970) (out= 90)(deflated 98%)
361          adding: 3.au(in = 11616) (out= 108)(deflated 99%)
362          adding: Animator.class(in = 2266) (out= 66)(deflated 97%)
363          adding: Wave.class(in = 3778) (out= 81)(deflated 97%)
364          adding: at_work.gif(in = 6621) (out= 89)(deflated 98%)
365          adding: monkey.jpg(in = 7667) (out= 91)(deflated 98%)
366          adding: spacemusic.au(in = 3079) (out= 73)(deflated 97%)
367
368
369       If you already have separate subdirectories for images, audio files and
370       classes, you can combine them into a single jar file:
371
372
373          % ls -F
374          audio/ classes/ images/
375
376          % jar cvf bundle.jar audio classes images
377          added manifest
378          adding: audio/(in = 0) (out= 0)(stored 0%)
379          adding: audio/1.au(in = 2324) (out= 67)(deflated 97%)
380          adding: audio/2.au(in = 6970) (out= 90)(deflated 98%)
381          adding: audio/3.au(in = 11616) (out= 108)(deflated 99%)
382          adding: audio/spacemusic.au(in = 3079) (out= 73)(deflated 97%)
383          adding: classes/(in = 0) (out= 0)(stored 0%)
384          adding: classes/Animator.class(in = 2266) (out= 66)(deflated 97%)
385          adding: classes/Wave.class(in = 3778) (out= 81)(deflated 97%)
386          adding: images/(in = 0) (out= 0)(stored 0%)
387          adding: images/monkey.jpg(in = 7667) (out= 91)(deflated 98%)
388          adding: images/at_work.gif(in = 6621) (out= 89)(deflated 98%)
389
390          % ls -F
391          audio/ bundle.jar classes/ images/
392
393
394       To see the entry names in the jarfile, use the t option:
395
396
397          % jar tf bundle.jar
398          META-INF/
399          META-INF/MANIFEST.MF
400          audio/1.au
401          audio/2.au
402          audio/3.au
403          audio/spacemusic.au
404          classes/Animator.class
405          classes/Wave.class
406          images/monkey.jpg
407          images/at_work.gif
408
409
410       To add an index file to the jar file for speeding up class loading, use
411       the i option.
412       Example:
413
414
415          If you split the inter-dependent classes for a stock trade applica‐
416          tion into three jar files: main.jar, buy.jar, and sell.jar.
417
418
419          If you specify the Class-path attribute in the main.jar manifest as:
420          Class-Path: buy.jar sell.jar
421
422
423          then you can use the -i option to speed up the class loading time
424          for your application:
425          % jar i main.jar
426
427
428          An INDEX.LIST file is inserted to the META-INF directory. This
429          enables the application class loader to download the specified jar
430          files when it is searching for classes or resources.
431

SEE ALSO

433       The Jar Overview @
434       http://ccc.sfbay/guide/jar/jarGuide.html
435
436
437       The Jar File Specification @
438       http://ccc.sfbay/guide/jar/jar.html
439
440
441       The JarIndex Spec @
442       http://ccc.sfbay/guide/jar/jar.html#JAR%20Index
443
444
445       Jar Tutorial @
446       http://java.sun.com/docs/books/tutorial/jar on the Java Software web
447       site.
448
449
450       pack200 Reference Page @
451       http://ccc.sfbay/4291383/share/pack200.html
452
453                                  05 Aug 2006                           jar(1)
Impressum