1jar(1)                            Basic Tools                           jar(1)
2
3
4

NAME

6       jar - Manipulates Java Archive (JAR) files.
7

SYNOPSIS

9       Create JAR file
10
11
12       jar c[efmMnv0] [entrypoint] [jarfile] [manifest] [-C dir] file ... [-Joption ...] [@arg-file ...]
13
14
15       Update JAR file
16
17
18       jar u[efmMnv0] [entrypoint] [jarfile] [manifest] [-C dir] file ... [-Joption ...] [@arg-file ...]
19
20
21       Extract JAR file
22
23
24       jar x[vf] [jarfile] file ... [-Joption ...] [@arg-file ...]
25
26
27       List Contents of JAR file
28
29
30       jar t[vf] [jarfile] file ... [-Joption ...] [@arg-file ...]
31
32
33       Add Index to JAR file
34
35
36       jar i jarfile [-Joption ...] [@arg-file ...]
37
38

DESCRIPTION

40       The jar command is a general-purpose archiving and compression tool,
41       based on ZIP and the ZLIB compression format. However, the jar command
42       was designed mainly to package Java applets or applications into a
43       single archive. When the components of an applet or application (files,
44       images and sounds) are combined into a single archive, they can be
45       downloaded by a Java agent (such as a browser) in a single HTTP
46       transaction, rather than requiring a new connection for each piece.
47       This dramatically improves download times. The jar command also
48       compresses files, which further improves download time. The jar command
49       also allows individual entries in a file to be signed by the applet
50       author so that their origin can be authenticated. A JAR file can be
51       used as a class path entry, whether or not it is compressed.
52
53       The syntax for the jar command resembles the syntax for the tar
54       command. It has several operation modes, defined by one of the
55       mandatory operation arguments. Other arguments are either options that
56       modify the behavior of the operation, or operands required to perform
57       the operation.
58

OPERATION ARGUMENTS

60       When using the jar command, you have to select an operation to be
61       performed by specifying one of the following operation arguments. You
62       can mix them up with other one-letter options on the command line, but
63       usually the operation argument is the first argument specified.
64
65       c      Create a new JAR archive.
66
67       i      Generate index information for a JAR archive.
68
69       t      List the contents of a JAR archive.
70
71       u      Update a JAR archive.
72
73       x      Extract files from a JAR archive.
74

OPTIONS

76       Use the following options to customize how the JAR file is created,
77       updated, extracted, or viewed:
78
79       e      Sets the class specified by the entrypoint operand to be the
80              entry point for a standalone Java application bundled into an
81              executable JAR file. The use of this option creates or overrides
82              the Main-Class attribute value in the manifest file. The e
83              option can be used when creating (c) or updating (u) the JAR
84              file.
85
86              For example, the following command creates the Main.jar archive
87              with the Main.class file where the Main-Class attribute value in
88              the manifest is set to Main:
89
90              jar cfe Main.jar Main Main.class
91
92
93
94              The Java Runtime Environment (JRE) can directly call this
95              application by running the following command:
96
97              java -jar Main.jar
98
99
100
101              If the entry point class name is in a package, then it could use
102              either the dot (.) or slash (/) as the delimiter. For example,
103              if Main.class is in a package called mydir, then the entry point
104              can be specified in one of the following ways:
105
106              jar -cfe Main.jar mydir/Main mydir/Main.class
107              jar -cfe Main.jar mydir.Main mydir/Main.class
108
109
110
111              Note
112
113              Specifying both m and e options together when a particular
114              manifest also contains the Main-Class attribute results in an
115              ambiguous Main-Class specification. The ambiguity leads to an
116              error and the jar command creation or update operation is
117              terminated.
118
119       f      Sets the file specified by the jarfile operand to be the name of
120              the JAR file that is created (c), updated (u), extracted (x)
121              from, or viewed (t). Omitting the f option and the jarfile
122              operand instructs the jar command to accept the JAR file name
123              from stdin (for x and t) or send the JAR file to stdout (for c
124              and u).
125
126       m      Includes names and values of attributes from the file specified
127              by the manifest operand in the manifest file of the jar command
128              (located in the archive at META-INF/MANIFEST.MF). The jar
129              command adds the attribute’s name and value to the JAR file
130              unless an entry already exists with the same name, in which case
131              the jar command updates the value of the attribute. The m option
132              can be used when creating (c) or updating (u) the JAR file.
133
134              You can add special-purpose name-value attribute pairs to the
135              manifest that are not contained in the default manifest file.
136              For example, you can add attributes that specify vendor
137              information, release information, package sealing, or to make
138              JAR-bundled applications executable. For examples of using the m
139              option, see Packaging Programs at
140              http://docs.oracle.com/javase/tutorial/deployment/jar/index.html
141
142       M      Does not create a manifest file entry (for c and u), or delete a
143              manifest file entry when one exists (for u). The M option can be
144              used when creating (c) or updating (u) the JAR file.
145
146       n      When creating (c) a JAR file, this option normalizes the archive
147              so that the content is not affected by the packing and unpacking
148              operations of the pack200(1) command. Without this
149              normalization, the signature of a signed JAR can become invalid.
150
151       v      Generates verbose output to standard output. See Examples.
152
153       0      (Zero) Creates (c) or updates (u) the JAR file without using ZIP
154              compression.
155
156       -C dir
157              When creating (c) or updating (u) a JAR file, this option
158              temporarily changes the directory while processing files
159              specified by the file operands. Its operation is intended to be
160              similar to the -C option of the UNIX tar utility.For example,
161              the following command changes to the classes directory and adds
162              the Bar.class file from that directory to my.jar:
163
164              jar uf my.jar -C classes Bar.class
165
166
167
168              The following command changes to the classes directory and adds
169              to my.jar all files within the classes directory (without
170              creating a classes directory in the JAR file), then changes back
171              to the original directory before changing to the bin directory
172              to add Xyz.class to my.jar.
173
174              jar uf my.jar -C classes . -C bin Xyz.class
175
176
177
178              If classes contained files bar1 and bar2, then the JAR file will
179              contain the following after running the previous command:
180
181              % jar tf my.jar
182              META-INF/
183              META-INF/MANIFEST.MF
184              bar1
185              bar2
186              Xyz.class
187
188
189
190       -Joption
191              Sets the specified JVM option to be used when the JRE runs the
192              JAR file. JVM options are described on the reference page for
193              the java(1) command. For example, -J-Xms48m sets the startup
194              memory to 48 MB.
195

OPERANDS

197       The following operands are recognized by the jar command.
198
199       file   When creating (c) or updating (u) a JAR file, the file operand
200              defines the path and name of the file or directory that should
201              be added to the archive. When extracting (x) or listing the
202              contents (t) of a JAR file, the file operand defines the path
203              and name of the file to be extrated or listed. At least one
204              valid file or directory must be specified. Separate multiple
205              file operands with spaces. If the entrypoint, jarfile, or
206              manifest operands are used, the file operands must be specified
207              after them.
208
209       entrypoint
210              When creating (c) or updating (u) a JAR file, the entrypoint
211              operand defines the name of the class that should be the entry
212              point for a standalone Java application bundled into an
213              executable JAR file. The entrypoint operand must be specified if
214              the e option is present.
215
216       jarfile
217              Defines the name of the file to be created (c), updated (u),
218              extracted (x), or viewed (t). The jarfile operand must be
219              specified if the f option is present. Omitting the f option and
220              the jarfile operand instructs the jar command to accept the JAR
221              file name from stdin (for x and t) or send the JAR file to
222              stdout (for c and u).
223
224              When indexing (i) a JAR file, specify the jarfile operand
225              without the f option.
226
227       manifest
228              When creating (c) or updating (u) a JAR file, the manifest
229              operand defines the preexisting manifest files with names and
230              values of attributes to be included in MANIFEST.MF in the JAR
231              file. The manifest operand must be specified if the f option is
232              present.
233
234       @arg-file
235              To shorten or simplify the jar command, you can specify
236              arguments in a separate text file and pass it to the jar command
237              with the at sign (@) as a prefix. When the jar command
238              encounters an argument beginning with the at sign, it expands
239              the contents of that file into the argument list.
240
241              An argument file can include options and arguments of the jar
242              command (except the -J options, because they are passed to the
243              launcher, which does not support argument files). The arguments
244              within a file can be separated by spaces or newline characters.
245              File names within an argument file are relative to the current
246              directory from which you run the jar command, not relative to
247              the location of the argument file. Wild cards, such as the
248              asterisk (*), that might otherwise be expanded by the operating
249              system shell, are not expanded.
250
251              The following example, shows how to create a classes.list file
252              with names of files from the current directory output by the
253              find command:
254
255              find . -name '*.class' -print > classes.list
256
257
258
259              You can then execute the jar command and pass the classes.list
260              file to it using the @arg-file syntax:
261
262              jar cf my.jar @classes.list
263
264
265
266              An argument file can be specified with a path, but any file
267              names inside the argument file that have relative paths are
268              relative to the current working directory of the jar command,
269              not to the path passed in, for example:
270
271              jar @dir/classes.list
272
273
274

NOTES

276       The e, f, and m options must appear in the same order on the command
277       line as the entrypoint, jarfile, and manifest operands, for example:
278
279       jar cmef myManifestFile MyMainClass myFile.jar *.class
280
281

EXAMPLES

283       Example 1 Adding All Files From the Current Directory With Verbose
284       Output
285
286       % ls
287       1.au          Animator.class    monkey.jpg
288       2.au          Wave.class        spacemusic.au
289       3.au          at_work.gif
290       % jar cvf bundle.jar *
291       added manifest
292       adding: 1.au(in = 2324) (out= 67)(deflated 97%)
293       adding: 2.au(in = 6970) (out= 90)(deflated 98%)
294       adding: 3.au(in = 11616) (out= 108)(deflated 99%)
295       adding: Animator.class(in = 2266) (out= 66)(deflated 97%)
296       adding: Wave.class(in = 3778) (out= 81)(deflated 97%)
297       adding: at_work.gif(in = 6621) (out= 89)(deflated 98%)
298       adding: monkey.jpg(in = 7667) (out= 91)(deflated 98%)
299       adding: spacemusic.au(in = 3079) (out= 73)(deflated 97%)
300
301       Example 2 Adding Files From Subdirectories
302
303       % ls -F
304       audio/ classes/ images/
305       % jar cvf bundle.jar audio classes images
306       added manifest
307       adding: audio/(in = 0) (out= 0)(stored 0%)
308       adding: audio/1.au(in = 2324) (out= 67)(deflated 97%)
309       adding: audio/2.au(in = 6970) (out= 90)(deflated 98%)
310       adding: audio/3.au(in = 11616) (out= 108)(deflated 99%)
311       adding: audio/spacemusic.au(in = 3079) (out= 73)(deflated 97%)
312       adding: classes/(in = 0) (out= 0)(stored 0%)
313       adding: classes/Animator.class(in = 2266) (out= 66)(deflated 97%)
314       adding: classes/Wave.class(in = 3778) (out= 81)(deflated 97%)
315       adding: images/(in = 0) (out= 0)(stored 0%)
316       adding: images/monkey.jpg(in = 7667) (out= 91)(deflated 98%)
317       adding: images/at_work.gif(in = 6621) (out= 89)(deflated 98%)
318       % ls -F
319       audio/ bundle.jar classes/ images/
320
321       Example 3 Listing the Contents of JAR
322
323       % jar tf bundle.jar
324
325
326       META-INF/
327       META-INF/MANIFEST.MF
328       audio/1.au
329       audio/2.au
330       audio/3.au
331       audio/spacemusic.au
332       classes/Animator.class
333       classes/Wave.class
334       images/monkey.jpg
335       images/at_work.gif
336
337       Example 4 Adding an Index
338
339       Use the i option when you split the interdependent classes for a stock
340       trade application into three JAR files: main.jar, buy.jar, and
341       sell.jar. If you specify the Class-Path attribute in the main.jar
342       manifest, then you can use the i option to speed up the class loading
343       time for your application:
344
345       Class-Path: buy.jar sell.jar
346       jar i main.jar
347
348       An INDEX.LIST file is inserted to the META-INF directory. This enables
349       the application class loader to download the specified JAR files when
350       it is searching for classes or resources.
351
352       The application class loader uses the information stored in this file
353       for efficient class loading. To copy directories, first compress files
354       in dir1 to stdout, then pipeline and extract from stdin to dir2
355       (omitting the -f option from both jar commands):
356
357       (cd dir1; jar c .) | (cd dir2; jar x)
358
359

SEE ALSO

361       · pack200(1).
362
363       · The JAR section of The Java Tutorials at
364         http://docs.oracle.com/javase/tutorial/deployment/jar/index.html
365
366
367
368JDK 8                          21 November 2013                         jar(1)
Impressum