jar.1 revision 6073:cea72c2bf071
1." Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
2." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3."
4." This code is free software; you can redistribute it and/or modify it
5." under the terms of the GNU General Public License version 2 only, as
6." published by the Free Software Foundation.
7."
8." This code is distributed in the hope that it will be useful, but WITHOUT
9." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11." version 2 for more details (a copy is included in the LICENSE file that
12." accompanied this code).
13."
14." You should have received a copy of the GNU General Public License version
15." 2 along with this work; if not, write to the Free Software Foundation,
16." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17."
18." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19." or visit www.oracle.com if you need additional information or have any
20." questions.
21."
22.TH jar 1 "10 May 2011"
23
24.LP
25.SH "Name"
26jar\-The Java Archive Tool
27.LP
28\f3jar\fP combines multiple files into a single JAR archive file.
29.SH "SYNOPSIS"
30.LP
31.RS 3
32.TP 3
33Create jar file
34\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
35.TP 3
36Update jar file
37\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
38.TP 3
39Extract jar file
40\f4jar x\fP\f2[vf] [\fP\f2jarfile\fP\f2] [\fP\f2inputfiles\fP\f2] [\-J\fP\f2option\fP\f2]\fP
41.TP 3
42List table of contents of jar file
43\f4jar t\fP\f2[vf] [\fP\f2jarfile\fP\f2] [\fP\f2inputfiles\fP\f2] [\-J\fP\f2option\fP\f2]\fP
44.TP 3
45Add index to jar file
46\f4jar i\fP \f2jarfile\fP \f2[\-J\fP\f2option\fP\f2]\fP
47.RE
48
49.LP
50.LP
51where:
52.LP
53.RS 3
54.TP 3
55cuxtiv0Mmfe
56Options that control the \f2jar\fP command.
57.TP 3
58jarfile
59Jar 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).
60.TP 3
61inputfiles
62Files 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.
63.TP 3
64manifest
65Pre\-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.
66.TP 3
67entrypoint
68The 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.
69.TP 3
70\-C\ dir
71Temporarily changes directories to \f2dir\fP while processing the following \f2inputfiles\fP argument. Multiple \f2\-C\ \fP\f2dir\fP \f2inputfiles\fP sets are allowed.
72.TP 3
73\-Joption
74Option to be passed into the Java runtime environment. (There must be no space between \f2\-J\fP and \f2option\fP).
75.RE
76
77.LP
78.SH "DESCRIPTION"
79.LP
80The \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
81.na
82\f2ZLIB\fP @
83.fi
84http://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.
85.LP
86Typical usage to combine files into a jar file is:
87.LP
88.nf
89\f3
90.fl
91% jar cf myFile.jar *.class
92.fl
93\fP
94.fi
95
96.LP
97In 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
98.na
99\f2JAR file specification\fP @
100.fi
101http://download.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR%20Manifest for details explaining how the jar tool stores meta\-information in the manifest file.
102.LP
103If a jar file should include \f2name\ :\ value\fP pairs contained in an existing manifest file, specify that file using the \f2\-m\fP option:
104.LP
105.nf
106\f3
107.fl
108% jar cmf myManifestFile myFile.jar *.class
109.fl
110\fP
111.fi
112
113.LP
114An 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.
115.br
116
117.LP
118.br
119
120.LP
121\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:
122.nf
123\f3
124.fl
125% jar cfm myFile.jar myManifestFile *.class
126.fl
127\fP
128.fi
129
130.LP
131The manifest is in a text format inspired by RFC822 ASCII format, so it is easy to view and process manifest\-file contents.
132.LP
133To extract the files from a jar file, use \f2x\fP:
134.LP
135.nf
136\f3
137.fl
138% jar xf myFile.jar
139.fl
140\fP
141.fi
142
143.LP
144.LP
145To extract individual files from a jar file, supply their filenames:
146.LP
147.nf
148\f3
149.fl
150% jar xf myFile.jar foo bar
151.fl
152\fP
153.fi
154
155.LP
156.LP
157Beginning with version 1.3 of the JDK, the \f2jar\fP utility supports
158.na
159\f2JarIndex\fP @
160.fi
161http://download.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Index, 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.
162.LP
163.nf
164\f3
165.fl
166% jar i main.jar
167.fl
168\fP
169.fi
170
171.LP
172.LP
173In this example, an \f2INDEX.LIST\fP file is inserted into the \f2META\-INF\fP directory of \f2main.jar\fP.
174.br
175.br
176The 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.
177.br
178.br
179To 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):
180.LP
181.nf
182\f3
183.fl
184% (cd dir1; jar c .) | (cd dir2; jar x)
185.fl
186\fP
187.fi
188
189.LP
190.LP
191To 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
192.na
193\f2Java Tutorial\fP @
194.fi
195http://download.oracle.com/javase/tutorial/deployment/jar.
196.LP
197.SH "OPTIONS"
198.LP
199.RS 3
200.TP 3
201c
202Creates 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.
203.TP 3
204u
205Updates an existing file \f2jarfile\fP (when \f2f\fP is specified) by adding to it files and directories specified by \f2inputfiles\fP. For example:
206.nf
207\f3
208.fl
209jar uf foo.jar foo.class
210.fl
211\fP
212.fi
213would 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:
214.nf
215\f3
216.fl
217jar umf manifest foo.jar
218.fl
219\fP
220.fi
221updates the \f2foo.jar\fP manifest with the \f2name : value\fP pairs in \f2manifest\fP.
222.TP 3
223x
224Extracts 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.
225.TP 3
226t
227Lists 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.
228.TP 3
229i
230Generate index information for the specified \f2jarfile\fP and its dependent jar files. For example:
231.nf
232\f3
233.fl
234jar i foo.jar
235.fl
236\fP
237.fi
238.LP
239would 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.
240.TP 3
241f
242Specifies 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).
243.TP 3
244v
245Generates verbose output to standard output. Examples shown below.
246.TP 3
2470
248(zero) Store without using ZIP compression.
249.TP 3
250M
251Do not create a manifest file entry (for c and u), or delete a manifest file entry if one exists (for u).
252.TP 3
253m
254Includes \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.
255.br
256.br
257On 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:
258.nf
259\f3
260.fl
261jar cmf myManifestFile myFile.jar *.class
262.fl
263\fP
264.fi
265You 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
266.na
267\f2JAR Files\fP @
268.fi
269http://download.oracle.com/javase/tutorial/deployment/jar/ trail in the Java Tutorial  for examples of using the \f4\-m\fP option.
270.TP 3
271e
272Sets \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.
273.br
274.br
275.br
276For example, this command creates \f2Main.jar\fP where the \f2Main\-Class\fP attribute value in the manifest is set to \f2Main\fP:
277.nf
278\f3
279.fl
280jar cfe Main.jar Main Main.class
281.fl
282\fP
283.fi
284The java runtime can directly invoke this application by running the following command:
285.nf
286\f3
287.fl
288java \-jar Main.jar
289.fl
290\fP
291.fi
292If 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:
293.nf
294\f3
295.fl
296jar \-cfe Main.jar foo/Main foo/Main.class
297.fl
298\fP
299.fi
300or
301.nf
302\f3
303.fl
304jar \-cfe Main.jar foo.Main foo/Main.class
305.fl
306\fP
307.fi
308\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.
309.TP 3
310\-C\ dir
311Temporarily 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.
312.br
313.br
314For example, this command changes to the \f2classes\fP directory and adds the \f2bar.class\fP from that directory to \f2foo.jar\fP:
315.nf
316\f3
317.fl
318jar uf foo.jar \-C classes bar.class
319.fl
320\fP
321.fi
322This 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.
323.nf
324\f3
325.fl
326jar uf foo.jar \-C classes . \-C bin xyz.class
327.fl
328\fP
329.fi
330If \f2classes\fP holds files \f2bar1\fP and \f2bar2\fP, then here's what the jar file will contain using \f2jar tf foo.jar\fP:
331.nf
332\f3
333.fl
334META\-INF/
335.fl
336META\-INF/MANIFEST.MF
337.fl
338bar1
339.fl
340bar2
341.fl
342xyz.class
343.fl
344\fP
345.fi
346.LP
347.TP 3
348\-Joption
349Pass \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.
350.RE
351
352.LP
353.SH "COMMAND LINE ARGUMENT FILES"
354.LP
355To 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.
356.LP
357An 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.
358.LP
359.LP
360When 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.
361.br
362.br
363The example below, \f2classes.list\fP holds the names of files output by a \f2find\fP command:
364.LP
365.nf
366\f3
367.fl
368% find \fP\f3.\fP \-name '*.class' \-print > classes.list
369.fl
370.fi
371
372.LP
373.LP
374You can then execute the \f2jar\fP command on \f2Classes.list\fP by passing it to \f2jar\fP using argfile syntax:
375.LP
376.nf
377\f3
378.fl
379% jar cf my.jar @classes.list
380.fl
381\fP
382.fi
383
384.LP
385An 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:
386.nf
387\f3
388.fl
389% jar @path1/classes.list
390.fl
391\fP
392.fi
393
394.LP
395.LP
396
397.LP
398.SH "EXAMPLES"
399.LP
400To 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.
401.nf
402\f3
403.fl
404% ls
405.fl
4061.au          Animator.class    monkey.jpg
407.fl
4082.au          Wave.class        spacemusic.au
409.fl
4103.au          at_work.gif
411.fl
412
413.fl
414% jar cvf bundle.jar *
415.fl
416added manifest
417.fl
418adding: 1.au(in = 2324) (out= 67)(deflated 97%)
419.fl
420adding: 2.au(in = 6970) (out= 90)(deflated 98%)
421.fl
422adding: 3.au(in = 11616) (out= 108)(deflated 99%)
423.fl
424adding: Animator.class(in = 2266) (out= 66)(deflated 97%)
425.fl
426adding: Wave.class(in = 3778) (out= 81)(deflated 97%)
427.fl
428adding: at_work.gif(in = 6621) (out= 89)(deflated 98%)
429.fl
430adding: monkey.jpg(in = 7667) (out= 91)(deflated 98%)
431.fl
432adding: spacemusic.au(in = 3079) (out= 73)(deflated 97%)
433.fl
434\fP
435.fi
436
437.LP
438If you already have separate subdirectories for images, audio files and classes, you can combine them into a single jar file:
439.nf
440\f3
441.fl
442% ls \-F
443.fl
444audio/ classes/ images/
445.fl
446
447.fl
448% jar cvf bundle.jar audio classes images
449.fl
450added manifest
451.fl
452adding: audio/(in = 0) (out= 0)(stored 0%)
453.fl
454adding: audio/1.au(in = 2324) (out= 67)(deflated 97%)
455.fl
456adding: audio/2.au(in = 6970) (out= 90)(deflated 98%)
457.fl
458adding: audio/3.au(in = 11616) (out= 108)(deflated 99%)
459.fl
460adding: audio/spacemusic.au(in = 3079) (out= 73)(deflated 97%)
461.fl
462adding: classes/(in = 0) (out= 0)(stored 0%)
463.fl
464adding: classes/Animator.class(in = 2266) (out= 66)(deflated 97%)
465.fl
466adding: classes/Wave.class(in = 3778) (out= 81)(deflated 97%)
467.fl
468adding: images/(in = 0) (out= 0)(stored 0%)
469.fl
470adding: images/monkey.jpg(in = 7667) (out= 91)(deflated 98%)
471.fl
472adding: images/at_work.gif(in = 6621) (out= 89)(deflated 98%)
473.fl
474
475.fl
476% ls \-F
477.fl
478audio/ bundle.jar classes/ images/
479.fl
480\fP
481.fi
482
483.LP
484To see the entry names in the jarfile, use the \f2t\fP option:
485.nf
486\f3
487.fl
488% jar tf bundle.jar
489.fl
490META\-INF/
491.fl
492META\-INF/MANIFEST.MF
493.fl
494audio/1.au
495.fl
496audio/2.au
497.fl
498audio/3.au
499.fl
500audio/spacemusic.au
501.fl
502classes/Animator.class
503.fl
504classes/Wave.class
505.fl
506images/monkey.jpg
507.fl
508images/at_work.gif
509.fl
510\fP
511.fi
512
513.LP
514.LP
515To add an index file to the jar file for speeding up class loading, use the \f2i\fP option.
516.br
517.br
518Example:
519.br
520
521.LP
522If 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.
523.br
524
525.LP
526.br
527
528.LP
529If you specify the \f2Class\-path\fP attribute in the \f2main.jar\fP manifest as:
530.nf
531\f3
532.fl
533Class\-Path: buy.jar sell.jar
534.fl
535\fP
536.fi
537
538.LP
539then you can use the \f2\-i\fP option to speed up the class loading time for your application:
540.nf
541\f3
542.fl
543% jar i main.jar
544.fl
545\fP
546.fi
547
548.LP
549An \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.
550.SH "SEE ALSO"
551.LP
552.LP
553.na
554\f2The Jar Overview\fP @
555.fi
556http://download.oracle.com/javase/7/docs/technotes/guides/jar/jarGuide.html
557.LP
558.LP
559.na
560\f2The Jar File Specification\fP @
561.fi
562http://download.oracle.com/javase/7/docs/technotes/guides/jar/jar.html
563.LP
564.LP
565.na
566\f2The JarIndex Spec\fP @
567.fi
568http://download.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Index
569.LP
570.LP
571.na
572\f2Jar Tutorial\fP @
573.fi
574http://download.oracle.com/javase/tutorial/deployment/jar/index.html
575.LP
576.LP
577pack200(1)
578.LP
579
580