blob: e559e47a160eb86ac1acdff6b5387e82e7cc5992 [file] [log] [blame]
rgallardb6435452013-11-25 20:19:02 -08001'\" t
2.\" Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3.\"
4.\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.\"
6.\" This code is free software; you can redistribute it and/or modify it
7.\" under the terms of the GNU General Public License version 2 only, as
8.\" published by the Free Software Foundation.
9.\"
10.\" This code is distributed in the hope that it will be useful, but WITHOUT
11.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13.\" version 2 for more details (a copy is included in the LICENSE file that
14.\" accompanied this code).
15.\"
16.\" You should have received a copy of the GNU General Public License version
17.\" 2 along with this work; if not, write to the Free Software Foundation,
18.\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19.\"
20.\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21.\" or visit www.oracle.com if you need additional information or have any
22.\" questions.
23.\"
24.\" Arch: generic
25.\" Software: JDK 8
26.\" Date: 21 November 2013
27.\" SectDesc: Basic Tools
28.\" Title: jar.1
29.\"
30.if n .pl 99999
31.TH jar 1 "21 November 2013" "JDK 8" "Basic Tools"
32.\" -----------------------------------------------------------------
33.\" * Define some portability stuff
34.\" -----------------------------------------------------------------
35.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36.\" http://bugs.debian.org/507673
37.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
38.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39.ie \n(.g .ds Aq \(aq
40.el .ds Aq '
41.\" -----------------------------------------------------------------
42.\" * set default formatting
43.\" -----------------------------------------------------------------
44.\" disable hyphenation
45.nh
46.\" disable justification (adjust text to left margin only)
47.ad l
48.\" -----------------------------------------------------------------
49.\" * MAIN CONTENT STARTS HERE *
50.\" -----------------------------------------------------------------
tbell16c34dd2009-05-04 18:28:26 -070051
rgallardb6435452013-11-25 20:19:02 -080052.SH NAME
53jar \- Manipulates Java Archive (JAR) files\&.
54.SH SYNOPSIS
55Create JAR file
56.sp
57.nf
tbell16c34dd2009-05-04 18:28:26 -070058
rgallardb6435452013-11-25 20:19:02 -080059\fBjar c\fR[\fBefmMnv0\fR] [\fIentrypoint\fR] [\fIjarfile\fR] [\fImanifest\fR] [\fB\-C\fR \fIdir\fR] \fIfile\fR \&.\&.\&. [\-J\fIoption\fR \&.\&.\&.] [@\fIarg\-file\fR \&.\&.\&.]
60.fi
61.sp
tbell16c34dd2009-05-04 18:28:26 -070062
rgallardb6435452013-11-25 20:19:02 -080063Update JAR file
64.sp
65.nf
duke6e45e102007-12-01 00:00:00 +000066
rgallardb6435452013-11-25 20:19:02 -080067\fBjar u\fR[\fBefmMnv0\fR] [\fIentrypoint\fR] [\fIjarfile\fR] [\fImanifest\fR] [\fB\-C\fR \fIdir\fR] \fIfile\fR \&.\&.\&. [\-J\fIoption\fR \&.\&.\&.] [@\fIarg\-file\fR \&.\&.\&.]
68.fi
69.sp
duke6e45e102007-12-01 00:00:00 +000070
rgallardb6435452013-11-25 20:19:02 -080071Extract JAR file
72.sp
73.nf
74
75\fBjar\fR \fBx\fR[\fBvf\fR] [\fIjarfile\fR] \fIfile\fR \&.\&.\&. [\-J\fIoption\fR \&.\&.\&.] [@\fIarg\-file\fR \&.\&.\&.]
76.fi
77.sp
78
79List Contents of JAR file
80.sp
81.nf
82
83\fBjar\fR \fBt\fR[\fBvf\fR] [\fIjarfile\fR] \fIfile\fR \&.\&.\&. [\-J\fIoption\fR \&.\&.\&.] [@\fIarg\-file\fR \&.\&.\&.]
84.fi
85.sp
86
87Add Index to JAR file
88.sp
89.nf
90
91\fBjar\fR \fBi\fR \fIjarfile\fR [\-J\fIoption\fR \&.\&.\&.] [@\fIarg\-file\fR \&.\&.\&.]
92.fi
93.sp
94.SH DESCRIPTION
95The \f3jar\fR command is a general-purpose archiving and compression tool, based on ZIP and the ZLIB compression format\&. However, the \f3jar\fR command was designed mainly to 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 (such as a browser) in a single HTTP transaction, rather than requiring a new connection for each piece\&. This dramatically improves download times\&. The \f3jar\fR command also compresses files, which further improves download time\&. The \f3jar\fR command also allows individual entries in a file to be signed by the applet author so that their origin can be authenticated\&. A JAR file can be used as a class path entry, whether or not it is compressed\&.
96.PP
97The syntax for the \f3jar\fR command resembles the syntax for the \f3tar\fR command\&. It has several operation modes, defined by one of the mandatory \fIoperation arguments\fR\&. Other arguments are either \fIoptions\fR that modify the behavior of the operation, or \fIoperands\fR required to perform the operation\&.
98.SH OPERATION\ ARGUMENTS
99When using the \f3jar\fR command, you have to select an operation to be performed by specifying one of the following operation arguments\&. You can mix them up with other one-letter options on the command line, but usually the operation argument is the first argument specified\&.
100.TP
101c
102Create a new JAR archive\&.
103.TP
104i
105Generate index information for a JAR archive\&.
106.TP
107t
108List the contents of a JAR archive\&.
109.TP
110u
111Update a JAR archive\&.
112.TP
113x
114Extract files from a JAR archive\&.
115.SH OPTIONS
116Use the following options to customize how the JAR file is created, updated, extracted, or viewed:
117.TP
118e
119Sets the class specified by the \fIentrypoint\fR operand to be the entry point\f3\fR for a standalone Java application bundled into an executable JAR file\&. The use of this option creates or overrides the \f3Main-Class\fR attribute value in the manifest file\&. The \f3e\fR option can be used when creating (\f3c\fR) or updating (\f3u\fR) the JAR file\&.
120
121For example, the following command creates the \f3Main\&.jar\fR archive with the \f3Main\&.class\fR file where the \f3Main-Clas\fRs attribute value in the manifest is set to \f3Main\fR:
122.sp
123.nf
124\f3jar cfe Main\&.jar Main Main\&.class\fP
125.fi
126.nf
127\f3\fP
128.fi
129.sp
130
131
132The Java Runtime Environment (JRE) can directly call this application by running the following command:
133.sp
134.nf
135\f3java \-jar Main\&.jar\fP
136.fi
137.nf
138\f3\fP
139.fi
140.sp
141
142
143If the entry point class name is in a package, then it could use either the dot (\&.) or slash (/) as the delimiter\&. For example, if \f3Main\&.class\fR is in a package called \f3mydir\fR, then the entry point can be specified in one of the following ways:
144.sp
145.nf
146\f3jar \-cfe Main\&.jar mydir/Main mydir/Main\&.class\fP
147.fi
148.nf
149\f3jar \-cfe Main\&.jar mydir\&.Main mydir/Main\&.class\fP
150.fi
151.nf
152\f3\fP
153.fi
154.sp
155
156
157Note
158
159Specifying both \f3m\fR and \f3e\fR options together when a particular manifest also contains the \f3Main-Class\fR attribute results in an ambiguous \f3Main-Class\fR specification\&. The ambiguity leads to an error and the \f3jar\fR command creation or update operation is terminated\&.
160.TP
161f
162Sets the file specified by the \fI\fR\fIjarfile\fR operand to be the name of the JAR file that is created (\f3c\fR), updated (\f3u\fR), extracted (\f3x\fR) from, or viewed (\f3t\fR)\&. Omitting the \f3f\fR option and the \fIjarfile\fR operand instructs the \f3jar\fR command to accept the JAR file name from \f3stdin\fR (for \f3x\fR and \f3t\fR) or send the JAR \f3\fRfile to \f3stdout\fR (for \f3c\fR and \f3u\fR)\&.
163.TP
164m
165Includes names and values of attributes from the file specified by the \f3manifest\fR operand in the manifest file of the \f3jar\fR command (located in the archive at \f3META-INF/MANIFEST\&.MF\fR)\&. The \f3jar\fR command adds the attribute\(cqs name and value to the JAR file unless an entry already exists with the same name, in which case the \f3jar\fR command updates the value of the attribute\&. The \f3m\fR option can be used when creating (\f3c\fR) or updating (\f3u\fR) the JAR file\&.
166
167You can add special-purpose name-value attribute pairs to the manifest that are not contained in the default manifest file\&. For example, you can add attributes that specify vendor information, release information, package sealing, or to make JAR-bundled applications executable\&. For examples of using the \f3m\fR option, see Packaging Programs at http://docs\&.oracle\&.com/javase/tutorial/deployment/jar/index\&.html
168.TP
169M
170Does not create a manifest file entry (for \f3c\fR and \f3u\fR), or delete a manifest file entry when one exists (for \f3u\fR)\&. The \f3M\fR option can be used when creating (\f3c\fR) or updating (\f3u\fR) the JAR file\&.
171.TP
172n
173When creating (\f3c\fR) a JAR file, this option normalizes the archive so that the content is not affected by the packing and unpacking operations of the pack200(1) command\&. Without this normalization, the signature of a signed JAR can become invalid\&.
174.TP
175v
176Generates verbose output to standard output\&. See Examples\&.
177.TP
1780
179(Zero) Creates (\f3c\fR) or updates (\f3u\fR) the JAR file without using ZIP compression\&.
180.TP
181-C \fIdir\fR
duke6e45e102007-12-01 00:00:00 +0000182.br
rgallardb6435452013-11-25 20:19:02 -0800183When creating (\f3c\fR) or updating (\f3u\fR) a JAR file, this option temporarily changes the directory while processing files specified by the \fIfile\fR operands\&. Its operation is intended to be similar to the \f3-C\fR option of the UNIX \f3tar\fR utility\&.For example, the following command changes to the \f3classes\fR directory and adds the \f3Bar\&.class\fR file from that directory to \f3my\&.jar\fR:
184.sp
185.nf
186\f3jar uf my\&.jar \-C classes Bar\&.class\fP
187.fi
188.nf
189\f3\fP
190.fi
191.sp
duke6e45e102007-12-01 00:00:00 +0000192
duke6e45e102007-12-01 00:00:00 +0000193
rgallardb6435452013-11-25 20:19:02 -0800194The following command changes to the \f3classes\fR directory and adds to \f3my\&.jar\fR all files within the classes directory (without creating a \f3classes\fR directory in the JAR file), then changes back to the original directory before changing to the \f3bin\fR directory to add \f3Xyz\&.class\fR to \f3my\&.jar\fR\&.
195.sp
196.nf
197\f3jar uf my\&.jar \-C classes \&. \-C bin Xyz\&.class\fP
198.fi
199.nf
200\f3\fP
201.fi
202.sp
duke6e45e102007-12-01 00:00:00 +0000203
duke6e45e102007-12-01 00:00:00 +0000204
rgallardb6435452013-11-25 20:19:02 -0800205If \f3classes\fR contained files \f3bar1\fR and \f3bar2\fR, then the JAR file will contain the following after running the previous command:
206.sp
207.nf
208\f3% \fIjar tf my\&.jar\fR\fP
209.fi
210.nf
211\f3META\-INF/\fP
212.fi
213.nf
214\f3META\-INF/MANIFEST\&.MF\fP
215.fi
216.nf
217\f3bar1\fP
218.fi
219.nf
220\f3bar2\fP
221.fi
222.nf
223\f3Xyz\&.class\fP
224.fi
225.nf
226\f3\fP
227.fi
228.sp
duke6e45e102007-12-01 00:00:00 +0000229
rgallardb6435452013-11-25 20:19:02 -0800230.TP
231\fI\fR-J\fIoption\fR
232Sets the specified JVM option to be used when the JRE runs the JAR file\&. JVM options are described on the reference page for the java(1) command\&. For example, \f3-J-Xms48m\fR sets the startup memory to 48 MB\&.
233.SH OPERANDS
234The following operands are recognized by the \f3jar\fR command\&.
235.TP
236\fIfile\fR
237When creating (\f3c\fR) or updating (\f3u\fR) a JAR file, the \fIfile\fR operand defines the path and name of the file or directory that should be added to the archive\&. When extracting (\f3x\fR) or listing the contents (\f3t\fR) of a JAR file, the \fIfile\fR operand defines the path and name of the file to be extrated or listed\&. At least one valid file or directory must be specified\&. Separate multiple \fIfile\fR operands with spaces\&. If the \fIentrypoint\fR, \fIjarfile\fR, or \fImanifest\fR operands are used, the \fIfile\fR operands must be specified after them\&.
238.TP
239\fIentrypoint\fR
240When creating (\f3c\fR) or updating (\f3u\fR) a JAR file, the \fIentrypoint\fR operand defines the name of the class that should be the entry point\f3\fR for a standalone Java application bundled into an executable JAR file\&. The \fIentrypoint\fR operand must be specified if the \f3e\fR option is present\&.
241.TP
242\fIjarfile\fR
243Defines the name of the file to be created (\f3c\fR), updated (\f3u\fR), extracted (\f3x\fR), or viewed (\f3t\fR)\&. The \fIjarfile\fR operand must be specified if the \f3f\fR option is present\&. Omitting the \f3f\fR option and the \fIjarfile\fR operand instructs the \f3jar\fR command to accept the JAR file name from \f3stdin\fR (for \f3x\fR and \f3t\fR) or send the JAR \f3\fRfile to \f3stdout\fR (for \f3c\fR and \f3u\fR)\&.
duke6e45e102007-12-01 00:00:00 +0000244
rgallardb6435452013-11-25 20:19:02 -0800245When indexing (\f3i\fR) a JAR file, specify the \fIjarfile\fR operand without the \f3f\fR option\&.
246.TP
247\fImanifest\fR
248When creating (\f3c\fR) or updating (\f3u\fR) a JAR file, the \fImanifest\fR operand defines the preexisting manifest files with names and values of attributes to be included in \f3MANIFEST\&.MF\fR in the JAR file\&. The \fImanifest\fR operand must be specified if the \f3f\fR option is present\&.
249.TP
250\fI@arg-file\fR
251To shorten or simplify the \f3jar\fR command, you can specify arguments in a separate text file and pass it to the \f3jar\fR command with the at sign (@) as a prefix\&. When the \f3jar\fR command encounters an argument beginning with the at sign, it expands the contents of that file into the argument list\&.
duke6e45e102007-12-01 00:00:00 +0000252
rgallardb6435452013-11-25 20:19:02 -0800253An argument file can include options and arguments of the \f3jar\fR command (except the \f3-J\fR options, because they are passed to the launcher, which does not support argument files)\&. The arguments within a file can be separated by spaces or newline characters\&. File names within an argument file are relative to the current directory from which you run the \f3jar\fR command, not relative to the location of the argument file\&. Wild cards, such as the asterisk (*), that might otherwise be expanded by the operating system shell, are not expanded\&.
tbell16c34dd2009-05-04 18:28:26 -0700254
rgallardb6435452013-11-25 20:19:02 -0800255The following example, shows how to create a \f3classes\&.list\fR file with names of files from the current directory output by the \f3find\fR command:
256.sp
257.nf
258\f3find \&. \-name \&'*\&.class\&' \-print > classes\&.list\fP
259.fi
260.nf
261\f3\fP
262.fi
263.sp
duke6e45e102007-12-01 00:00:00 +0000264
duke6e45e102007-12-01 00:00:00 +0000265
rgallardb6435452013-11-25 20:19:02 -0800266You can then execute the \f3jar\fR command and pass the \f3classes\&.list\fR file to it using the \fI@arg-file\fR syntax:
267.sp
268.nf
269\f3jar cf my\&.jar @classes\&.list\fP
270.fi
271.nf
272\f3\fP
273.fi
274.sp
duke6e45e102007-12-01 00:00:00 +0000275
duke6e45e102007-12-01 00:00:00 +0000276
rgallardb6435452013-11-25 20:19:02 -0800277An argument file can be specified with a path, but any file names inside the argument file that have relative paths are relative to the current working directory of the \f3jar\fR command, not to the path passed in, for example:
278.sp
279.nf
280\f3jar @dir/classes\&.list\fP
281.fi
282.nf
283\f3\fP
284.fi
285.sp
duke6e45e102007-12-01 00:00:00 +0000286
rgallardb6435452013-11-25 20:19:02 -0800287.SH NOTES
288The \f3e\fR, \f3f\fR, and \f3m\fR options must appear in the same order on the command line as the \fIentrypoint\fR, \fIjarfile\fR, and \fImanifest\fR operands, for example:
289.sp
290.nf
291\f3jar cmef myManifestFile MyMainClass myFile\&.jar *\&.class\fP
292.fi
293.nf
294\f3\fP
295.fi
296.sp
297.SH EXAMPLES
298\f3Example 1 Adding All Files From the Current Directory With Verbose Output\fR
299.sp
300.nf
301\f3% ls\fP
302.fi
303.nf
304\f31\&.au Animator\&.class monkey\&.jpg\fP
305.fi
306.nf
307\f32\&.au Wave\&.class spacemusic\&.au\fP
308.fi
309.nf
310\f33\&.au at_work\&.gif\fP
311.fi
312.nf
313\f3\fP
314.fi
315.nf
316\f3% jar cvf bundle\&.jar *\fP
317.fi
318.nf
319\f3added manifest\fP
320.fi
321.nf
322\f3adding: 1\&.au(in = 2324) (out= 67)(deflated 97%)\fP
323.fi
324.nf
325\f3adding: 2\&.au(in = 6970) (out= 90)(deflated 98%)\fP
326.fi
327.nf
328\f3adding: 3\&.au(in = 11616) (out= 108)(deflated 99%)\fP
329.fi
330.nf
331\f3adding: Animator\&.class(in = 2266) (out= 66)(deflated 97%)\fP
332.fi
333.nf
334\f3adding: Wave\&.class(in = 3778) (out= 81)(deflated 97%)\fP
335.fi
336.nf
337\f3adding: at_work\&.gif(in = 6621) (out= 89)(deflated 98%)\fP
338.fi
339.nf
340\f3adding: monkey\&.jpg(in = 7667) (out= 91)(deflated 98%)\fP
341.fi
342.nf
343\f3adding: spacemusic\&.au(in = 3079) (out= 73)(deflated 97%)\fP
344.fi
345.nf
346\f3\fP
347.fi
348.sp
349\f3Example 2 Adding Files From Subdirectories\fR
350.sp
351.nf
352\f3% ls \-F\fP
353.fi
354.nf
355\f3audio/ classes/ images/\fP
356.fi
357.nf
358\f3% jar cvf bundle\&.jar audio classes images\fP
359.fi
360.nf
361\f3added manifest\fP
362.fi
363.nf
364\f3adding: audio/(in = 0) (out= 0)(stored 0%)\fP
365.fi
366.nf
367\f3adding: audio/1\&.au(in = 2324) (out= 67)(deflated 97%)\fP
368.fi
369.nf
370\f3adding: audio/2\&.au(in = 6970) (out= 90)(deflated 98%)\fP
371.fi
372.nf
373\f3adding: audio/3\&.au(in = 11616) (out= 108)(deflated 99%)\fP
374.fi
375.nf
376\f3adding: audio/spacemusic\&.au(in = 3079) (out= 73)(deflated 97%)\fP
377.fi
378.nf
379\f3adding: classes/(in = 0) (out= 0)(stored 0%)\fP
380.fi
381.nf
382\f3adding: classes/Animator\&.class(in = 2266) (out= 66)(deflated 97%)\fP
383.fi
384.nf
385\f3adding: classes/Wave\&.class(in = 3778) (out= 81)(deflated 97%)\fP
386.fi
387.nf
388\f3adding: images/(in = 0) (out= 0)(stored 0%)\fP
389.fi
390.nf
391\f3adding: images/monkey\&.jpg(in = 7667) (out= 91)(deflated 98%)\fP
392.fi
393.nf
394\f3adding: images/at_work\&.gif(in = 6621) (out= 89)(deflated 98%)\fP
395.fi
396.nf
397\f3\fP
398.fi
399.nf
400\f3% ls \-F\fP
401.fi
402.nf
403\f3audio/ bundle\&.jar classes/ images/\fP
404.fi
405.nf
406\f3\fP
407.fi
408.sp
409\f3Example 3 Listing the Contents of JAR\fR
410.sp
411.nf
412\f3% jar tf bundle\&.jar\fP
413.fi
414.sp
415.sp
416.nf
417\f3META\-INF/\fP
418.fi
419.nf
420\f3META\-INF/MANIFEST\&.MF\fP
421.fi
422.nf
423\f3audio/1\&.au\fP
424.fi
425.nf
426\f3audio/2\&.au\fP
427.fi
428.nf
429\f3audio/3\&.au\fP
430.fi
431.nf
432\f3audio/spacemusic\&.au\fP
433.fi
434.nf
435\f3classes/Animator\&.class\fP
436.fi
437.nf
438\f3classes/Wave\&.class\fP
439.fi
440.nf
441\f3images/monkey\&.jpg\fP
442.fi
443.nf
444\f3images/at_work\&.gif\fP
445.fi
446.nf
447\f3\fP
448.fi
449.sp
450\f3Example 4 Adding an Index\fR
451.PP
452Use the \f3i\fR option when you split the interdependent classes for a stock trade application into three JAR files: \f3main\&.jar\fR, \f3buy\&.jar\fR, and \f3sell\&.jar\fR\&. If you specify the \f3Class-Path\fR attribute in the \f3main\&.jar\fR manifest, then you can use the \f3i\fR option to speed up the class loading time for your application:
453.sp
454.nf
455\f3Class\-Path: buy\&.jar sell\&.jar\fP
456.fi
457.nf
458\f3jar i main\&.jar\fP
459.fi
460.nf
461\f3\fP
462.fi
463.sp
464An \f3INDEX\&.LIST\fR file is inserted to the \f3META-INF\fR directory\&. This enables the application class loader to download the specified JAR files when it is searching for classes or resources\&.
465.PP
466The application class loader uses the information stored in this file for efficient class loading\&. To copy directories, first compress files in \f3dir1\fR to \f3stdout\fR, then pipeline and extract from \f3stdin\fR to \f3dir2\fR (omitting the \f3-f\fR option from both \f3jar\fR commands):
467.sp
468.nf
469\f3(cd dir1; jar c \&.) | (cd dir2; jar x)\fP
470.fi
471.nf
472\f3\fP
473.fi
474.sp
475.SH SEE\ ALSO
476.TP 0.2i
477\(bu
478pack200(1)\&.
479.TP 0.2i
480\(bu
481The JAR section of The Java Tutorials at http://docs\&.oracle\&.com/javase/tutorial/deployment/jar/index\&.html
482.RE
483.br
484'pl 8.5i
485'bp