12047
|
1 |
." Copyright (c) 1997, 2011, 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"
|
|
26 |
jar\-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
|
|
33 |
Create 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
|
|
36 |
Update 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
|
|
39 |
Extract 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
|
|
42 |
List 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
|
|
45 |
Add index to jar file
|
|
46 |
\f4jar i\fP \f2jarfile\fP \f2[\-J\fP\f2option\fP\f2]\fP
|
|
47 |
.RE
|
|
48 |
|
|
49 |
.LP
|
|
50 |
.LP
|
|
51 |
where:
|
|
52 |
.LP
|
|
53 |
.RS 3
|
|
54 |
.TP 3
|
|
55 |
cuxtiv0Mmfe
|
|
56 |
Options that control the \f2jar\fP command.
|
|
57 |
.TP 3
|
|
58 |
jarfile
|
|
59 |
Jar 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
|
|
61 |
inputfiles
|
|
62 |
Files 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
|
|
64 |
manifest
|
|
65 |
Pre\-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
|
|
67 |
entrypoint
|
|
68 |
The 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
|
|
71 |
Temporarily 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
|
|
74 |
Option 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
|
|
80 |
The \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
|
|
84 |
http://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
|
|
86 |
Typical 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
|
|
97 |
In 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
|
|
101 |
http://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
|
|
103 |
If 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
|
|
114 |
An 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
|
|
131 |
The manifest is in a text format inspired by RFC822 ASCII format, so it is easy to view and process manifest\-file contents.
|
|
132 |
.LP
|
|
133 |
To 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
|
|
145 |
To 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
|
|
157 |
Beginning with version 1.3 of the JDK, the \f2jar\fP utility supports
|
|
158 |
.na
|
|
159 |
\f2JarIndex\fP @
|
|
160 |
.fi
|
|
161 |
http://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
|
|
173 |
In this example, an \f2INDEX.LIST\fP file is inserted into the \f2META\-INF\fP directory of \f2main.jar\fP.
|
|
174 |
.br
|
|
175 |
.br
|
|
176 |
The 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
|
|
179 |
To 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
|
|
191 |
To 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
|
|
195 |
http://download.oracle.com/javase/tutorial/deployment/jar.
|
|
196 |
.LP
|
|
197 |
.SH "OPTIONS"
|
|
198 |
.LP
|
|
199 |
.RS 3
|
|
200 |
.TP 3
|
|
201 |
c
|
|
202 |
Creates 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
|
|
204 |
u
|
|
205 |
Updates 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
|
|
209 |
jar uf foo.jar foo.class
|
|
210 |
.fl
|
|
211 |
\fP
|
|
212 |
.fi
|
|
213 |
would 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
|
|
217 |
jar umf manifest foo.jar
|
|
218 |
.fl
|
|
219 |
\fP
|
|
220 |
.fi
|
|
221 |
updates the \f2foo.jar\fP manifest with the \f2name : value\fP pairs in \f2manifest\fP.
|
|
222 |
.TP 3
|
|
223 |
x
|
|
224 |
Extracts 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
|
|
226 |
t
|
|
227 |
Lists 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
|
|
229 |
i
|
|
230 |
Generate index information for the specified \f2jarfile\fP and its dependent jar files. For example:
|
|
231 |
.nf
|
|
232 |
\f3
|
|
233 |
.fl
|
|
234 |
jar i foo.jar
|
|
235 |
.fl
|
|
236 |
\fP
|
|
237 |
.fi
|
|
238 |
.LP
|
|
239 |
would 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
|
|
241 |
f
|
|
242 |
Specifies 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
|
|
244 |
v
|
|
245 |
Generates verbose output to standard output. Examples shown below.
|
|
246 |
.TP 3
|
|
247 |
0
|
|
248 |
(zero) Store without using ZIP compression.
|
|
249 |
.TP 3
|
|
250 |
M
|
|
251 |
Do not create a manifest file entry (for c and u), or delete a manifest file entry if one exists (for u).
|
|
252 |
.TP 3
|
|
253 |
m
|
|
254 |
Includes \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
|
|
257 |
On 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
|
|
261 |
jar cmf myManifestFile myFile.jar *.class
|
|
262 |
.fl
|
|
263 |
\fP
|
|
264 |
.fi
|
|
265 |
You 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
|
|
269 |
http://download.oracle.com/javase/tutorial/deployment/jar/ trail in the Java Tutorial for examples of using the \f4\-m\fP option.
|
|
270 |
.TP 3
|
|
271 |
e
|
|
272 |
Sets \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
|
|
276 |
For 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
|
|
280 |
jar cfe Main.jar Main Main.class
|
|
281 |
.fl
|
|
282 |
\fP
|
|
283 |
.fi
|
|
284 |
The java runtime can directly invoke this application by running the following command:
|
|
285 |
.nf
|
|
286 |
\f3
|
|
287 |
.fl
|
|
288 |
java \-jar Main.jar
|
|
289 |
.fl
|
|
290 |
\fP
|
|
291 |
.fi
|
|
292 |
If 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
|
|
296 |
jar \-cfe Main.jar foo/Main foo/Main.class
|
|
297 |
.fl
|
|
298 |
\fP
|
|
299 |
.fi
|
|
300 |
or
|
|
301 |
.nf
|
|
302 |
\f3
|
|
303 |
.fl
|
|
304 |
jar \-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
|
|
311 |
Temporarily 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
|
|
314 |
For 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
|
|
318 |
jar uf foo.jar \-C classes bar.class
|
|
319 |
.fl
|
|
320 |
\fP
|
|
321 |
.fi
|
|
322 |
This 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
|
|
326 |
jar uf foo.jar \-C classes . \-C bin xyz.class
|
|
327 |
.fl
|
|
328 |
\fP
|
|
329 |
.fi
|
|
330 |
If \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
|
|
334 |
META\-INF/
|
|
335 |
.fl
|
|
336 |
META\-INF/MANIFEST.MF
|
|
337 |
.fl
|
|
338 |
bar1
|
|
339 |
.fl
|
|
340 |
bar2
|
|
341 |
.fl
|
|
342 |
xyz.class
|
|
343 |
.fl
|
|
344 |
\fP
|
|
345 |
.fi
|
|
346 |
.LP
|
|
347 |
.TP 3
|
|
348 |
\-Joption
|
|
349 |
Pass \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
|
|
355 |
To 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
|
|
357 |
An argument file can include options and filenames. The arguments within a file can be space\-separated or newline\-separated. Filenames within an argument file are relative to the current directory, not 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
|
|
360 |
When 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
|
|
363 |
The 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
|
|
374 |
You 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
|
|
385 |
An 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
|
|
400 |
To 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
|
|
406 |
1.au Animator.class monkey.jpg
|
|
407 |
.fl
|
|
408 |
2.au Wave.class spacemusic.au
|
|
409 |
.fl
|
|
410 |
3.au at_work.gif
|
|
411 |
.fl
|
|
412 |
|
|
413 |
.fl
|
|
414 |
% jar cvf bundle.jar *
|
|
415 |
.fl
|
|
416 |
added manifest
|
|
417 |
.fl
|
|
418 |
adding: 1.au(in = 2324) (out= 67)(deflated 97%)
|
|
419 |
.fl
|
|
420 |
adding: 2.au(in = 6970) (out= 90)(deflated 98%)
|
|
421 |
.fl
|
|
422 |
adding: 3.au(in = 11616) (out= 108)(deflated 99%)
|
|
423 |
.fl
|
|
424 |
adding: Animator.class(in = 2266) (out= 66)(deflated 97%)
|
|
425 |
.fl
|
|
426 |
adding: Wave.class(in = 3778) (out= 81)(deflated 97%)
|
|
427 |
.fl
|
|
428 |
adding: at_work.gif(in = 6621) (out= 89)(deflated 98%)
|
|
429 |
.fl
|
|
430 |
adding: monkey.jpg(in = 7667) (out= 91)(deflated 98%)
|
|
431 |
.fl
|
|
432 |
adding: spacemusic.au(in = 3079) (out= 73)(deflated 97%)
|
|
433 |
.fl
|
|
434 |
\fP
|
|
435 |
.fi
|
|
436 |
|
|
437 |
.LP
|
|
438 |
If 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
|
|
444 |
audio/ classes/ images/
|
|
445 |
.fl
|
|
446 |
|
|
447 |
.fl
|
|
448 |
% jar cvf bundle.jar audio classes images
|
|
449 |
.fl
|
|
450 |
added manifest
|
|
451 |
.fl
|
|
452 |
adding: audio/(in = 0) (out= 0)(stored 0%)
|
|
453 |
.fl
|
|
454 |
adding: audio/1.au(in = 2324) (out= 67)(deflated 97%)
|
|
455 |
.fl
|
|
456 |
adding: audio/2.au(in = 6970) (out= 90)(deflated 98%)
|
|
457 |
.fl
|
|
458 |
adding: audio/3.au(in = 11616) (out= 108)(deflated 99%)
|
|
459 |
.fl
|
|
460 |
adding: audio/spacemusic.au(in = 3079) (out= 73)(deflated 97%)
|
|
461 |
.fl
|
|
462 |
adding: classes/(in = 0) (out= 0)(stored 0%)
|
|
463 |
.fl
|
|
464 |
adding: classes/Animator.class(in = 2266) (out= 66)(deflated 97%)
|
|
465 |
.fl
|
|
466 |
adding: classes/Wave.class(in = 3778) (out= 81)(deflated 97%)
|
|
467 |
.fl
|
|
468 |
adding: images/(in = 0) (out= 0)(stored 0%)
|
|
469 |
.fl
|
|
470 |
adding: images/monkey.jpg(in = 7667) (out= 91)(deflated 98%)
|
|
471 |
.fl
|
|
472 |
adding: images/at_work.gif(in = 6621) (out= 89)(deflated 98%)
|
|
473 |
.fl
|
|
474 |
|
|
475 |
.fl
|
|
476 |
% ls \-F
|
|
477 |
.fl
|
|
478 |
audio/ bundle.jar classes/ images/
|
|
479 |
.fl
|
|
480 |
\fP
|
|
481 |
.fi
|
|
482 |
|
|
483 |
.LP
|
|
484 |
To 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
|
|
490 |
META\-INF/
|
|
491 |
.fl
|
|
492 |
META\-INF/MANIFEST.MF
|
|
493 |
.fl
|
|
494 |
audio/1.au
|
|
495 |
.fl
|
|
496 |
audio/2.au
|
|
497 |
.fl
|
|
498 |
audio/3.au
|
|
499 |
.fl
|
|
500 |
audio/spacemusic.au
|
|
501 |
.fl
|
|
502 |
classes/Animator.class
|
|
503 |
.fl
|
|
504 |
classes/Wave.class
|
|
505 |
.fl
|
|
506 |
images/monkey.jpg
|
|
507 |
.fl
|
|
508 |
images/at_work.gif
|
|
509 |
.fl
|
|
510 |
\fP
|
|
511 |
.fi
|
|
512 |
|
|
513 |
.LP
|
|
514 |
.LP
|
|
515 |
To add an index file to the jar file for speeding up class loading, use the \f2i\fP option.
|
|
516 |
.br
|
|
517 |
.br
|
|
518 |
Example:
|
|
519 |
.br
|
|
520 |
|
|
521 |
.LP
|
|
522 |
If 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
|
|
529 |
If you specify the \f2Class\-path\fP attribute in the \f2main.jar\fP manifest as:
|
|
530 |
.nf
|
|
531 |
\f3
|
|
532 |
.fl
|
|
533 |
Class\-Path: buy.jar sell.jar
|
|
534 |
.fl
|
|
535 |
\fP
|
|
536 |
.fi
|
|
537 |
|
|
538 |
.LP
|
|
539 |
then 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
|
|
549 |
An \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
|
|
556 |
http://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
|
|
562 |
http://download.oracle.com/javase/7/docs/technotes/guides/jar/jar.html
|
|
563 |
.LP
|
|
564 |
.LP
|
|
565 |
.na
|
|
566 |
\f2The JarIndex Spec\fP @
|
|
567 |
.fi
|
|
568 |
http://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
|
|
574 |
http://download.oracle.com/javase/tutorial/deployment/jar/index.html
|
|
575 |
.LP
|
|
576 |
.LP
|
|
577 |
pack200(1)
|
|
578 |
.LP
|
|
579 |
|