18 .\" |
17 .\" |
19 .\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
18 .\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 .\" or visit www.oracle.com if you need additional information or have any |
19 .\" or visit www.oracle.com if you need additional information or have any |
21 .\" questions. |
20 .\" questions. |
22 .\" |
21 .\" |
23 .\" Arch: generic |
22 .\" Automatically generated by Pandoc 2.3.1 |
24 .\" Software: JDK 8 |
23 .\" |
25 .\" Date: 21 November 2013 |
24 .TH "JAR" "1" "2018" "JDK 13" "JDK Commands" |
26 .\" SectDesc: Basic Tools |
25 .hy |
27 .\" Title: jar.1 |
26 .SH NAME |
28 .\" |
27 .PP |
29 .if n .pl 99999 |
28 jar \- create an archive for classes and resources, and manipulate or |
30 .TH jar 1 "21 November 2013" "JDK 8" "Basic Tools" |
29 restore individual classes or resources from an archive |
31 .\" ----------------------------------------------------------------- |
30 .SH SYNOPSIS |
32 .\" * Define some portability stuff |
31 .PP |
33 .\" ----------------------------------------------------------------- |
32 \f[CB]jar\f[R] [\f[I]OPTION\f[R] ...] [ [\f[CB]\-\-release\f[R] |
34 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
33 \f[I]VERSION\f[R]] [\f[CB]\-C\f[R] \f[I]dir\f[R]] \f[I]files\f[R]] ... |
35 .\" http://bugs.debian.org/507673 |
34 .SH DESCRIPTION |
36 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
35 .PP |
37 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
36 The \f[CB]jar\f[R] command is a general\-purpose archiving and compression |
38 .ie \n(.g .ds Aq \(aq |
37 tool, based on the ZIP and ZLIB compression formats. |
39 .el .ds Aq ' |
38 Initially, the \f[CB]jar\f[R] command was designed to package Java applets |
40 .\" ----------------------------------------------------------------- |
39 (not supported since JDK 11) or applications; however, beginning with |
41 .\" * set default formatting |
40 JDK 9, users can use the \f[CB]jar\f[R] command to create modular JARs. |
42 .\" ----------------------------------------------------------------- |
41 For transportation and deployment, it\[aq]s usually more convenient to |
43 .\" disable hyphenation |
42 package modules as modular JARs. |
44 .nh |
43 .PP |
45 .\" disable justification (adjust text to left margin only) |
44 The syntax for the \f[CB]jar\f[R] command resembles the syntax for the |
46 .ad l |
45 \f[CB]tar\f[R] command. |
47 .\" ----------------------------------------------------------------- |
46 It has several main operation modes, defined by one of the mandatory |
48 .\" * MAIN CONTENT STARTS HERE * |
47 operation arguments. |
49 .\" ----------------------------------------------------------------- |
48 Other arguments are either options that modify the behavior of the |
|
49 operation or are required to perform the operation. |
|
50 .PP |
|
51 When modules or the components of an application (files, images and |
|
52 sounds) are combined into a single archive, they can be downloaded by a |
|
53 Java agent (such as a browser) in a single HTTP transaction, rather than |
|
54 requiring a new connection for each piece. |
|
55 This dramatically improves download times. |
|
56 The \f[CB]jar\f[R] command also compresses files, which further improves |
|
57 download time. |
|
58 The \f[CB]jar\f[R] command also enables individual entries in a file to be |
|
59 signed so that their origin can be authenticated. |
|
60 A JAR file can be used as a class path entry, whether or not it\[aq]s |
|
61 compressed. |
|
62 .PP |
|
63 An archive becomes a modular JAR when you include a module descriptor, |
|
64 \f[CB]module\-info.class\f[R], in the root of the given directories or in |
|
65 the root of the \f[CB]\&.jar\f[R] archive. |
|
66 The following operations described in \f[B]Operation Modifiers Valid |
|
67 Only in Create and Update Modes\f[R] are valid only when creating or |
|
68 updating a modular jar or updating an existing non\-modular jar: |
|
69 .IP \[bu] 2 |
|
70 \f[CB]\-\-module\-version\f[R] |
|
71 .IP \[bu] 2 |
|
72 \f[CB]\-\-hash\-modules\f[R] |
|
73 .IP \[bu] 2 |
|
74 \f[CB]\-\-module\-path\f[R] |
|
75 .PP |
|
76 \f[B]Note:\f[R] |
|
77 .PP |
|
78 All mandatory or optional arguments for long options are also mandatory |
|
79 or optional for any corresponding short options. |
|
80 .SH MAIN OPERATION MODES |
|
81 .PP |
|
82 When using the \f[CB]jar\f[R] command, you must specify the operation for |
|
83 it to perform. |
|
84 You specify the operation mode for the \f[CB]jar\f[R] command by including |
|
85 the appropriate operation arguments described in this section. |
|
86 You can mix an operation argument with other one\-letter options. |
|
87 Generally the operation argument is the first argument specified on the |
|
88 command line. |
|
89 .TP |
|
90 .B \f[CB]\-c\f[R] or \f[CB]\-\-create\f[R] |
|
91 Creates the archive. |
|
92 .RS |
|
93 .RE |
|
94 .TP |
|
95 .B \f[CB]\-i=\f[R]\f[I]FILE\f[R] or \f[CB]\-\-generate\-index=\f[R]\f[I]FILE\f[R] |
|
96 Generates index information for the specified JAR file. |
|
97 .RS |
|
98 .RE |
|
99 .TP |
|
100 .B \f[CB]\-t\f[R] or \f[CB]\-\-list\f[R] |
|
101 Lists the table of contents for the archive. |
|
102 .RS |
|
103 .RE |
|
104 .TP |
|
105 .B \f[CB]\-u\f[R] or \f[CB]\-\-update\f[R] |
|
106 Updates an existing JAR file. |
|
107 .RS |
|
108 .RE |
|
109 .TP |
|
110 .B \f[CB]\-x\f[R] or \f[CB]\-\-extract\f[R] |
|
111 Extracts the named (or all) files from the archive. |
|
112 .RS |
|
113 .RE |
|
114 .TP |
|
115 .B \f[CB]\-d\f[R] or \f[CB]\-\-describe\-module\f[R] |
|
116 Prints the module descriptor or automatic module name. |
|
117 .RS |
|
118 .RE |
|
119 .SH OPERATION MODIFIERS VALID IN ANY MODE |
|
120 .PP |
|
121 You can use the following options to customize the actions of any |
|
122 operation mode included in the \f[CB]jar\f[R] command. |
|
123 .TP |
|
124 .B \f[CB]\-C\f[R] \f[I]DIR\f[R] |
|
125 Changes the specified directory and includes the \f[I]files\f[R] |
|
126 specified at the end of the command line. |
|
127 .RS |
|
128 .PP |
|
129 \f[CB]jar\f[R] [\f[I]OPTION\f[R] ...] [ [\f[CB]\-\-release\f[R] |
|
130 \f[I]VERSION\f[R]] [\f[CB]\-C\f[R] \f[I]dir\f[R]] \f[I]files\f[R]] |
|
131 .RE |
|
132 .TP |
|
133 .B \f[CB]\-f=\f[R]\f[I]FILE\f[R] or \f[CB]\-\-file=\f[R]\f[I]FILE\f[R] |
|
134 Specifies the archive file name. |
|
135 .RS |
|
136 .RE |
|
137 .TP |
|
138 .B \f[CB]\-\-release\f[R] \f[I]VERSION\f[R] |
|
139 Creates a multirelease JAR file. |
|
140 Places all files specified after the option into a versioned directory |
|
141 of the JAR file named |
|
142 \f[CB]META\-INF/versions/\f[R]\f[I]VERSION\f[R]\f[CB]/\f[R], where |
|
143 \f[I]VERSION\f[R] must be must be a positive integer whose value is 9 or |
|
144 greater. |
|
145 .RS |
|
146 .PP |
|
147 At run time, where more than one version of a class exists in the JAR, |
|
148 the JDK will use the first one it finds, searching initially in the |
|
149 directory tree whose \f[I]VERSION\f[R] number matches the JDK\[aq]s major |
|
150 version number. |
|
151 It will then look in directories with successively lower |
|
152 \f[I]VERSION\f[R] numbers, and finally look in the root of the JAR. |
|
153 .RE |
|
154 .TP |
|
155 .B \f[CB]\-v\f[R] or \f[CB]\-\-verbose\f[R] |
|
156 Sends or prints verbose output to standard output. |
|
157 .RS |
|
158 .RE |
|
159 .SH OPERATION MODIFIERS VALID ONLY IN CREATE AND UPDATE MODES |
|
160 .PP |
|
161 You can use the following options to customize the actions of the create |
|
162 and the update main operation modes: |
|
163 .TP |
|
164 .B \f[CB]\-e=\f[R]\f[I]CLASSNAME\f[R] or \f[CB]\-\-main\-class=\f[R]\f[I]CLASSNAME\f[R] |
|
165 Specifies the application entry point for standalone applications |
|
166 bundled into a modular or executable modular JAR file. |
|
167 .RS |
|
168 .RE |
|
169 .TP |
|
170 .B \f[CB]\-m=\f[R]\f[I]FILE\f[R] or \f[CB]\-\-manifest=\f[R]\f[I]FILE\f[R] |
|
171 Includes the manifest information from the given manifest file. |
|
172 .RS |
|
173 .RE |
|
174 .TP |
|
175 .B \f[CB]\-M\f[R] or \f[CB]\-\-no\-manifest\f[R] |
|
176 Doesn\[aq]t create a manifest file for the entries. |
|
177 .RS |
|
178 .RE |
|
179 .TP |
|
180 .B \f[CB]\-\-module\-version=\f[R]\f[I]VERSION\f[R] |
|
181 Specifies the module version, when creating or updating a modular JAR |
|
182 file, or updating a non\-modular JAR file. |
|
183 .RS |
|
184 .RE |
|
185 .TP |
|
186 .B \f[CB]\-\-hash\-modules=\f[R]\f[I]PATTERN\f[R] |
|
187 Computes and records the hashes of modules matched by the given pattern |
|
188 and that depend upon directly or indirectly on a modular JAR file being |
|
189 created or a non\-modular JAR file being updated. |
|
190 .RS |
|
191 .RE |
|
192 .TP |
|
193 .B \f[CB]\-p\f[R] or \f[CB]\-\-module\-path\f[R] |
|
194 Specifies the location of module dependence for generating the hash. |
|
195 .RS |
|
196 .RE |
|
197 .TP |
|
198 .B \f[CB]\@\f[R]\f[I]file\f[R] |
|
199 Reads \f[CB]jar\f[R] options and file names from a text file. |
|
200 .RS |
|
201 .RE |
|
202 .SH OPERATION MODIFIERS VALID ONLY IN CREATE, UPDATE, AND |
|
203 GENERATE\-INDEX MODES |
|
204 .PP |
|
205 You can use the following options to customize the actions of the create |
|
206 (\f[CB]\-c\f[R] or \f[CB]\-\-create\f[R]) the update (\f[CB]\-u\f[R] or |
|
207 \f[CB]\-\-update\f[R] ) and the generate\-index (\f[CB]\-i\f[R] or |
|
208 \f[CB]\-\-generate\-index=\f[R]\f[I]FILE\f[R]) main operation modes: |
|
209 .TP |
|
210 .B \f[CB]\-0\f[R] or \f[CB]\-\-no\-compress\f[R] |
|
211 Stores without using ZIP compression. |
|
212 .RS |
|
213 .RE |
|
214 .SH OTHER OPTIONS |
|
215 .PP |
|
216 The following options are recognized by the \f[CB]jar\f[R] command and not |
|
217 used with operation modes: |
|
218 .TP |
|
219 .B \f[CB]\-h\f[R] or \f[CB]\-\-help\f[R][\f[CB]:compat\f[R]] |
|
220 Displays the command\-line help for the \f[CB]jar\f[R] command or |
|
221 optionally the compatibility help. |
|
222 .RS |
|
223 .RE |
|
224 .TP |
|
225 .B \f[CB]\-\-help\-extra\f[R] |
|
226 Displays help on extra options. |
|
227 .RS |
|
228 .RE |
|
229 .TP |
|
230 .B \f[CB]\-\-version\f[R] |
|
231 Prints the program version. |
|
232 .RS |
|
233 .RE |
|
234 .SH EXAMPLES OF JAR COMMAND SYNTAX |
|
235 .IP \[bu] 2 |
|
236 Create an archive, \f[CB]classes.jar\f[R], that contains two class files, |
|
237 \f[CB]Foo.class\f[R] and \f[CB]Bar.class\f[R]. |
|
238 .RS 2 |
|
239 .RS |
|
240 .PP |
|
241 \f[CB]jar\ \-\-create\ \-\-file\ classes.jar\ Foo.class\ Bar.class\f[R] |
|
242 .RE |
|
243 .RE |
|
244 .IP \[bu] 2 |
|
245 Create an archive, \f[CB]classes.jar\f[R], by using an existing manifest, |
|
246 \f[CB]mymanifest\f[R], that contains all of the files in the directory |
|
247 \f[CB]foo/\f[R]. |
|
248 .RS 2 |
|
249 .RS |
|
250 .PP |
|
251 \f[CB]jar\ \-\-create\ \-\-file\ classes.jar\ \-\-manifest\ mymanifest\ \-C\ foo/\f[R] |
|
252 .RE |
|
253 .RE |
|
254 .IP \[bu] 2 |
|
255 Create a modular JAR archive,\f[CB]foo.jar\f[R], where the module |
|
256 descriptor is located in \f[CB]classes/module\-info.class\f[R]. |
|
257 .RS 2 |
|
258 .RS |
|
259 .PP |
|
260 \f[CB]jar\ \-\-create\ \-\-file\ foo.jar\ \-\-main\-class\ com.foo.Main\ \-\-module\-version\ 1.0\ \-C\ foo/classes\ resources\f[R] |
|
261 .RE |
|
262 .RE |
|
263 .IP \[bu] 2 |
|
264 Update an existing non\-modular JAR, \f[CB]foo.jar\f[R], to a modular JAR |
|
265 file. |
|
266 .RS 2 |
|
267 .RS |
|
268 .PP |
|
269 \f[CB]jar\ \-\-update\ \-\-file\ foo.jar\ \-\-main\-class\ com.foo.Main\ \-\-module\-version\ 1.0\ \-C\ foo/module\-info.class\f[R] |
|
270 .RE |
|
271 .RE |
|
272 .IP \[bu] 2 |
|
273 Create a versioned or multi\-release JAR, \f[CB]foo.jar\f[R], that places |
|
274 the files in the \f[CB]classes\f[R] directory at the root of the JAR, and |
|
275 the files in the \f[CB]classes\-10\f[R] directory in the |
|
276 \f[CB]META\-INF/versions/10\f[R] directory of the JAR. |
|
277 .RS 2 |
|
278 .PP |
|
279 In this example, the \f[CB]classes/com/foo\f[R] directory contains two |
|
280 classes, \f[CB]com.foo.Hello\f[R] (the entry point class) and |
|
281 \f[CB]com.foo.NameProvider\f[R], both compiled for JDK 8. |
|
282 The \f[CB]classes\-10/com/foo\f[R] directory contains a different version |
|
283 of the \f[CB]com.foo.NameProvider\f[R] class, this one containing JDK 10 |
|
284 specific code and compiled for JDK 10. |
|
285 .PP |
|
286 Given this setup, create a multirelease JAR file \f[CB]foo.jar\f[R] by |
|
287 running the following command from the directory containing the |
|
288 directories \f[CB]classes\f[R] and \f[CB]classes\-10\f[R] . |
|
289 .RS |
|
290 .PP |
|
291 \f[CB]jar\ \-\-create\ \-\-file\ foo.jar\ \-\-main\-class\ com.foo.Hello\ \-C\ classes\ .\ \-\-release\ 10\ \-C\ classes\-10\ .\f[R] |
|
292 .RE |
|
293 .PP |
|
294 The JAR file \f[CB]foo.jar\f[R] now contains: |
|
295 .IP |
|
296 .nf |
|
297 \f[CB] |
|
298 %\ jar\ \-tf\ foo.jar |
50 |
299 |
51 .SH NAME |
300 META\-INF/ |
52 jar \- Manipulates Java Archive (JAR) files\&. |
301 META\-INF/MANIFEST.MF |
53 .SH SYNOPSIS |
302 com/ |
54 Create JAR file |
303 com/foo/ |
55 .sp |
304 com/foo/Hello.class |
56 .nf |
305 com/foo/NameProvider.class |
57 |
306 META\-INF/versions/10/com/ |
58 \fBjar c\fR[\fBefmMnv0\fR] [\fIentrypoint\fR] [\fIjarfile\fR] [\fImanifest\fR] [\fB\-C\fR \fIdir\fR] \fIfile\fR \&.\&.\&. [\-J\fIoption\fR \&.\&.\&.] [@\fIarg\-file\fR \&.\&.\&.] |
307 META\-INF/versions/10/com/foo/ |
59 .fi |
308 META\-INF/versions/10/com/foo/NameProvider.class |
60 .sp |
309 \f[R] |
61 |
310 .fi |
62 Update JAR file |
311 .PP |
63 .sp |
312 As well as other information, the file \f[CB]META\-INF/MANIFEST.MF\f[R], |
64 .nf |
313 will contain the following lines to indicate that this is a multirelease |
65 |
314 JAR file with an entry point of \f[CB]com.foo.Hello\f[R]. |
66 \fBjar u\fR[\fBefmMnv0\fR] [\fIentrypoint\fR] [\fIjarfile\fR] [\fImanifest\fR] [\fB\-C\fR \fIdir\fR] \fIfile\fR \&.\&.\&. [\-J\fIoption\fR \&.\&.\&.] [@\fIarg\-file\fR \&.\&.\&.] |
315 .IP |
67 .fi |
316 .nf |
68 .sp |
317 \f[CB] |
69 |
318 \&... |
70 Extract JAR file |
319 Main\-Class:\ com.foo.Hello |
71 .sp |
320 Multi\-Release:\ true |
72 .nf |
321 \f[R] |
73 |
322 .fi |
74 \fBjar\fR \fBx\fR[\fBvf\fR] [\fIjarfile\fR] \fIfile\fR \&.\&.\&. [\-J\fIoption\fR \&.\&.\&.] [@\fIarg\-file\fR \&.\&.\&.] |
323 .PP |
75 .fi |
324 Assuming that the \f[CB]com.foo.Hello\f[R] class calls a method on the |
76 .sp |
325 \f[CB]com.foo.NameProvider\f[R] class, running the program using JDK 10 |
77 |
326 will ensure that the \f[CB]com.foo.NameProvider\f[R] class is the one in |
78 List Contents of JAR file |
327 \f[CB]META\-INF/versions/10/com/foo/\f[R]. |
79 .sp |
328 Running the program using JDK 8 will ensure that the |
80 .nf |
329 \f[CB]com.foo.NameProvider\f[R] class is the one at the root of the JAR, |
81 |
330 in \f[CB]com/foo\f[R]. |
82 \fBjar\fR \fBt\fR[\fBvf\fR] [\fIjarfile\fR] \fIfile\fR \&.\&.\&. [\-J\fIoption\fR \&.\&.\&.] [@\fIarg\-file\fR \&.\&.\&.] |
331 .RE |
83 .fi |
332 .IP \[bu] 2 |
84 .sp |
333 Create an archive, \f[CB]my.jar\f[R], by reading options and lists of |
85 |
334 class files from the file \f[CB]classes.list\f[R]. |
86 Add Index to JAR file |
335 .RS 2 |
87 .sp |
336 .PP |
88 .nf |
337 \f[B]Note:\f[R] |
89 |
338 .PP |
90 \fBjar\fR \fBi\fR \fIjarfile\fR [\-J\fIoption\fR \&.\&.\&.] [@\fIarg\-file\fR \&.\&.\&.] |
339 To shorten or simplify the \f[CB]jar\f[R] command, you can specify |
91 .fi |
340 arguments in a separate text file and pass it to the \f[CB]jar\f[R] |
92 .sp |
341 command with the at sign (\f[CB]\@\f[R]) as a prefix. |
93 .SH DESCRIPTION |
342 .RS |
94 The \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\&. |
343 .PP |
95 .PP |
344 \f[CB]jar\ \-\-create\ \-\-file\ my.jar\ \@classes.list\f[R] |
96 The 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\&. |
345 .RE |
97 .SH OPERATION\ ARGUMENTS |
346 .RE |
98 When 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\&. |
|
99 .TP |
|
100 c |
|
101 Create a new JAR archive\&. |
|
102 .TP |
|
103 i |
|
104 Generate index information for a JAR archive\&. |
|
105 .TP |
|
106 t |
|
107 List the contents of a JAR archive\&. |
|
108 .TP |
|
109 u |
|
110 Update a JAR archive\&. |
|
111 .TP |
|
112 x |
|
113 Extract files from a JAR archive\&. |
|
114 .SH OPTIONS |
|
115 Use the following options to customize how the JAR file is created, updated, extracted, or viewed: |
|
116 .TP |
|
117 e |
|
118 Sets 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\&. |
|
119 |
|
120 For 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: |
|
121 .sp |
|
122 .nf |
|
123 \f3jar cfe Main\&.jar Main Main\&.class\fP |
|
124 .fi |
|
125 .nf |
|
126 \f3\fP |
|
127 .fi |
|
128 .sp |
|
129 |
|
130 |
|
131 The Java Runtime Environment (JRE) can directly call this application by running the following command: |
|
132 .sp |
|
133 .nf |
|
134 \f3java \-jar Main\&.jar\fP |
|
135 .fi |
|
136 .nf |
|
137 \f3\fP |
|
138 .fi |
|
139 .sp |
|
140 |
|
141 |
|
142 If 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: |
|
143 .sp |
|
144 .nf |
|
145 \f3jar \-cfe Main\&.jar mydir/Main mydir/Main\&.class\fP |
|
146 .fi |
|
147 .nf |
|
148 \f3jar \-cfe Main\&.jar mydir\&.Main mydir/Main\&.class\fP |
|
149 .fi |
|
150 .nf |
|
151 \f3\fP |
|
152 .fi |
|
153 .sp |
|
154 |
|
155 |
|
156 Note |
|
157 |
|
158 Specifying 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\&. |
|
159 .TP |
|
160 f |
|
161 Sets 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)\&. |
|
162 .TP |
|
163 m |
|
164 Includes 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\&. |
|
165 |
|
166 You 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 |
|
167 .TP |
|
168 M |
|
169 Does 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\&. |
|
170 .TP |
|
171 n |
|
172 When 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\&. |
|
173 .TP |
|
174 v |
|
175 Generates verbose output to standard output\&. See Examples\&. |
|
176 .TP |
|
177 0 |
|
178 (Zero) Creates (\f3c\fR) or updates (\f3u\fR) the JAR file without using ZIP compression\&. |
|
179 .TP |
|
180 -C \fIdir\fR |
|
181 .br |
|
182 When 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: |
|
183 .sp |
|
184 .nf |
|
185 \f3jar uf my\&.jar \-C classes Bar\&.class\fP |
|
186 .fi |
|
187 .nf |
|
188 \f3\fP |
|
189 .fi |
|
190 .sp |
|
191 |
|
192 |
|
193 The 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\&. |
|
194 .sp |
|
195 .nf |
|
196 \f3jar uf my\&.jar \-C classes \&. \-C bin Xyz\&.class\fP |
|
197 .fi |
|
198 .nf |
|
199 \f3\fP |
|
200 .fi |
|
201 .sp |
|
202 |
|
203 |
|
204 If \f3classes\fR contained files \f3bar1\fR and \f3bar2\fR, then the JAR file will contain the following after running the previous command: |
|
205 .sp |
|
206 .nf |
|
207 \f3% \fIjar tf my\&.jar\fR\fP |
|
208 .fi |
|
209 .nf |
|
210 \f3META\-INF/\fP |
|
211 .fi |
|
212 .nf |
|
213 \f3META\-INF/MANIFEST\&.MF\fP |
|
214 .fi |
|
215 .nf |
|
216 \f3bar1\fP |
|
217 .fi |
|
218 .nf |
|
219 \f3bar2\fP |
|
220 .fi |
|
221 .nf |
|
222 \f3Xyz\&.class\fP |
|
223 .fi |
|
224 .nf |
|
225 \f3\fP |
|
226 .fi |
|
227 .sp |
|
228 |
|
229 .TP |
|
230 \fI\fR-J\fIoption\fR |
|
231 Sets 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\&. |
|
232 .SH OPERANDS |
|
233 The following operands are recognized by the \f3jar\fR command\&. |
|
234 .TP |
|
235 \fIfile\fR |
|
236 When 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\&. |
|
237 .TP |
|
238 \fIentrypoint\fR |
|
239 When 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\&. |
|
240 .TP |
|
241 \fIjarfile\fR |
|
242 Defines 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)\&. |
|
243 |
|
244 When indexing (\f3i\fR) a JAR file, specify the \fIjarfile\fR operand without the \f3f\fR option\&. |
|
245 .TP |
|
246 \fImanifest\fR |
|
247 When 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\&. |
|
248 .TP |
|
249 \fI@arg-file\fR |
|
250 To 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\&. |
|
251 |
|
252 An 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\&. |
|
253 |
|
254 The 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: |
|
255 .sp |
|
256 .nf |
|
257 \f3find \&. \-name \&'*\&.class\&' \-print > classes\&.list\fP |
|
258 .fi |
|
259 .nf |
|
260 \f3\fP |
|
261 .fi |
|
262 .sp |
|
263 |
|
264 |
|
265 You can then execute the \f3jar\fR command and pass the \f3classes\&.list\fR file to it using the \fI@arg-file\fR syntax: |
|
266 .sp |
|
267 .nf |
|
268 \f3jar cf my\&.jar @classes\&.list\fP |
|
269 .fi |
|
270 .nf |
|
271 \f3\fP |
|
272 .fi |
|
273 .sp |
|
274 |
|
275 |
|
276 An 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: |
|
277 .sp |
|
278 .nf |
|
279 \f3jar @dir/classes\&.list\fP |
|
280 .fi |
|
281 .nf |
|
282 \f3\fP |
|
283 .fi |
|
284 .sp |
|
285 |
|
286 .SH NOTES |
|
287 The \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: |
|
288 .sp |
|
289 .nf |
|
290 \f3jar cmef myManifestFile MyMainClass myFile\&.jar *\&.class\fP |
|
291 .fi |
|
292 .nf |
|
293 \f3\fP |
|
294 .fi |
|
295 .sp |
|
296 .SH EXAMPLES |
|
297 \f3Example 1 Adding All Files From the Current Directory With Verbose Output\fR |
|
298 .sp |
|
299 .nf |
|
300 \f3% ls\fP |
|
301 .fi |
|
302 .nf |
|
303 \f31\&.au Animator\&.class monkey\&.jpg\fP |
|
304 .fi |
|
305 .nf |
|
306 \f32\&.au Wave\&.class spacemusic\&.au\fP |
|
307 .fi |
|
308 .nf |
|
309 \f33\&.au at_work\&.gif\fP |
|
310 .fi |
|
311 .nf |
|
312 \f3\fP |
|
313 .fi |
|
314 .nf |
|
315 \f3% jar cvf bundle\&.jar *\fP |
|
316 .fi |
|
317 .nf |
|
318 \f3added manifest\fP |
|
319 .fi |
|
320 .nf |
|
321 \f3adding: 1\&.au(in = 2324) (out= 67)(deflated 97%)\fP |
|
322 .fi |
|
323 .nf |
|
324 \f3adding: 2\&.au(in = 6970) (out= 90)(deflated 98%)\fP |
|
325 .fi |
|
326 .nf |
|
327 \f3adding: 3\&.au(in = 11616) (out= 108)(deflated 99%)\fP |
|
328 .fi |
|
329 .nf |
|
330 \f3adding: Animator\&.class(in = 2266) (out= 66)(deflated 97%)\fP |
|
331 .fi |
|
332 .nf |
|
333 \f3adding: Wave\&.class(in = 3778) (out= 81)(deflated 97%)\fP |
|
334 .fi |
|
335 .nf |
|
336 \f3adding: at_work\&.gif(in = 6621) (out= 89)(deflated 98%)\fP |
|
337 .fi |
|
338 .nf |
|
339 \f3adding: monkey\&.jpg(in = 7667) (out= 91)(deflated 98%)\fP |
|
340 .fi |
|
341 .nf |
|
342 \f3adding: spacemusic\&.au(in = 3079) (out= 73)(deflated 97%)\fP |
|
343 .fi |
|
344 .nf |
|
345 \f3\fP |
|
346 .fi |
|
347 .sp |
|
348 \f3Example 2 Adding Files From Subdirectories\fR |
|
349 .sp |
|
350 .nf |
|
351 \f3% ls \-F\fP |
|
352 .fi |
|
353 .nf |
|
354 \f3audio/ classes/ images/\fP |
|
355 .fi |
|
356 .nf |
|
357 \f3% jar cvf bundle\&.jar audio classes images\fP |
|
358 .fi |
|
359 .nf |
|
360 \f3added manifest\fP |
|
361 .fi |
|
362 .nf |
|
363 \f3adding: audio/(in = 0) (out= 0)(stored 0%)\fP |
|
364 .fi |
|
365 .nf |
|
366 \f3adding: audio/1\&.au(in = 2324) (out= 67)(deflated 97%)\fP |
|
367 .fi |
|
368 .nf |
|
369 \f3adding: audio/2\&.au(in = 6970) (out= 90)(deflated 98%)\fP |
|
370 .fi |
|
371 .nf |
|
372 \f3adding: audio/3\&.au(in = 11616) (out= 108)(deflated 99%)\fP |
|
373 .fi |
|
374 .nf |
|
375 \f3adding: audio/spacemusic\&.au(in = 3079) (out= 73)(deflated 97%)\fP |
|
376 .fi |
|
377 .nf |
|
378 \f3adding: classes/(in = 0) (out= 0)(stored 0%)\fP |
|
379 .fi |
|
380 .nf |
|
381 \f3adding: classes/Animator\&.class(in = 2266) (out= 66)(deflated 97%)\fP |
|
382 .fi |
|
383 .nf |
|
384 \f3adding: classes/Wave\&.class(in = 3778) (out= 81)(deflated 97%)\fP |
|
385 .fi |
|
386 .nf |
|
387 \f3adding: images/(in = 0) (out= 0)(stored 0%)\fP |
|
388 .fi |
|
389 .nf |
|
390 \f3adding: images/monkey\&.jpg(in = 7667) (out= 91)(deflated 98%)\fP |
|
391 .fi |
|
392 .nf |
|
393 \f3adding: images/at_work\&.gif(in = 6621) (out= 89)(deflated 98%)\fP |
|
394 .fi |
|
395 .nf |
|
396 \f3\fP |
|
397 .fi |
|
398 .nf |
|
399 \f3% ls \-F\fP |
|
400 .fi |
|
401 .nf |
|
402 \f3audio/ bundle\&.jar classes/ images/\fP |
|
403 .fi |
|
404 .nf |
|
405 \f3\fP |
|
406 .fi |
|
407 .sp |
|
408 \f3Example 3 Listing the Contents of JAR\fR |
|
409 .sp |
|
410 .nf |
|
411 \f3% jar tf bundle\&.jar\fP |
|
412 .fi |
|
413 .sp |
|
414 .sp |
|
415 .nf |
|
416 \f3META\-INF/\fP |
|
417 .fi |
|
418 .nf |
|
419 \f3META\-INF/MANIFEST\&.MF\fP |
|
420 .fi |
|
421 .nf |
|
422 \f3audio/1\&.au\fP |
|
423 .fi |
|
424 .nf |
|
425 \f3audio/2\&.au\fP |
|
426 .fi |
|
427 .nf |
|
428 \f3audio/3\&.au\fP |
|
429 .fi |
|
430 .nf |
|
431 \f3audio/spacemusic\&.au\fP |
|
432 .fi |
|
433 .nf |
|
434 \f3classes/Animator\&.class\fP |
|
435 .fi |
|
436 .nf |
|
437 \f3classes/Wave\&.class\fP |
|
438 .fi |
|
439 .nf |
|
440 \f3images/monkey\&.jpg\fP |
|
441 .fi |
|
442 .nf |
|
443 \f3images/at_work\&.gif\fP |
|
444 .fi |
|
445 .nf |
|
446 \f3\fP |
|
447 .fi |
|
448 .sp |
|
449 \f3Example 4 Adding an Index\fR |
|
450 .PP |
|
451 Use 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: |
|
452 .sp |
|
453 .nf |
|
454 \f3Class\-Path: buy\&.jar sell\&.jar\fP |
|
455 .fi |
|
456 .nf |
|
457 \f3jar i main\&.jar\fP |
|
458 .fi |
|
459 .nf |
|
460 \f3\fP |
|
461 .fi |
|
462 .sp |
|
463 An \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\&. |
|
464 .PP |
|
465 The 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): |
|
466 .sp |
|
467 .nf |
|
468 \f3(cd dir1; jar c \&.) | (cd dir2; jar x)\fP |
|
469 .fi |
|
470 .nf |
|
471 \f3\fP |
|
472 .fi |
|
473 .sp |
|
474 .SH SEE\ ALSO |
|
475 .TP 0.2i |
|
476 \(bu |
|
477 pack200(1)\&. |
|
478 .TP 0.2i |
|
479 \(bu |
|
480 The JAR section of The Java Tutorials at http://docs\&.oracle\&.com/javase/tutorial/deployment/jar/index\&.html |
|
481 .RE |
|
482 .br |
|
483 'pl 8.5i |
|
484 'bp |
|