jdk/src/linux/doc/man/jar.1
changeset 2 90ce3da70b43
child 2692 345bc8d65b19
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 .'" t
       
     2 ."
       
     3 ." Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
       
     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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    21 ." CA 95054 USA or visit www.sun.com if you need additional information or
       
    22 ." have any questions.
       
    23 ."
       
    24 ." `
       
    25 .TH jar 1 "05 Aug 2006"
       
    26 ." Generated by html2roff
       
    27 .\\"  Created by: Susan Keohan 30\-Oct\-1996 
       
    28 .\\"  Updated by: Beth Stearns 18\-Nov\-1996 
       
    29 .\\"  Updated by: Marianne Mueller 11\-Dec\-1996 
       
    30 .\\"  Updated by: Douglas Kramer 01\-Jul\-2003 
       
    31 .LP
       
    32 .SH NAME
       
    33 jar\-The Java Archive Tool
       
    34 .LP
       
    35 \f3jar\fP combines multiple files into a single JAR archive file.   
       
    36 .SH "SYNOPSIS"
       
    37 .LP
       
    38 
       
    39 .LP
       
    40 .TP 3
       
    41 Create jar file 
       
    42 \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 
       
    43 .TP 3
       
    44 Update jar file 
       
    45 \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 
       
    46 .TP 3
       
    47 Extract jar file 
       
    48 \f4jar x\fP\f2[vf] [\fP\f2jarfile\fP\f2] [\fP\f2inputfiles\fP\f2] [\-J\fP\f2option\fP\f2]\fP 
       
    49 .TP 3
       
    50 List table of contents of jar file 
       
    51 \f4jar t\fP\f2[vf] [\fP\f2jarfile\fP\f2] [\fP\f2inputfiles\fP\f2] [\-J\fP\f2option\fP\f2]\fP 
       
    52 .TP 3
       
    53 Add index to jar file 
       
    54 \f4jar i\fP \f2jarfile\fP \f2[\-J\fP\f2option\fP\f2]\fP 
       
    55 .LP
       
    56 .LP
       
    57 where:
       
    58 .LP
       
    59 .RS 3
       
    60 
       
    61 .LP
       
    62 .TP 3
       
    63 cuxtiv0Mmfe 
       
    64 Options that control the \f2jar\fP command. 
       
    65 .TP 3
       
    66  jarfile 
       
    67 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). 
       
    68 .TP 3
       
    69 
       
    70 inputfiles 
       
    71 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. 
       
    72 .TP 3
       
    73  manifest 
       
    74 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. 
       
    75 .TP 3
       
    76 
       
    77 entrypoint 
       
    78 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. 
       
    79 .TP 3
       
    80 \-C\ dir 
       
    81 Temporarily changes directories to \f2dir\fP while processing the following \f2inputfiles\fP argument. Multiple \f2\-C\ \fP\f2dir\fP \f2inputfiles\fP sets are allowed. 
       
    82 .TP 3
       
    83 \-Joption 
       
    84 Option to be passed into the Java runtime environment. (There must be no space between \f2\-J\fP and \f2option\fP). 
       
    85 .LP
       
    86 .RE
       
    87 .SH "DESCRIPTION"
       
    88 .LP
       
    89 
       
    90 .LP
       
    91 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 
       
    92 .na
       
    93 \f2ZLIB\fP @
       
    94 .fi
       
    95 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 
       
    96 .na
       
    97 \f2class path\fP @
       
    98 .fi
       
    99 http://ccc.sfbay/4291383/attachment/classpath.html entry, whether or not it is compressed. 
       
   100 .LP
       
   101 Typical usage to combine files into a jar file is:
       
   102 .LP
       
   103 .RS 3
       
   104 
       
   105 .LP
       
   106 .nf
       
   107 \f3
       
   108 .fl
       
   109 % jar cf myFile.jar *.class
       
   110 .fl
       
   111 \fP
       
   112 .fi
       
   113 .RE
       
   114 
       
   115 .LP
       
   116 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 
       
   117 .na
       
   118 \f2JAR file specification\fP @
       
   119 .fi
       
   120 http://ccc.sfbay/guide/jar/jar.html#JAR%20Manifest for details explaining how the jar tool stores meta\-information in the manifest file. 
       
   121 .LP
       
   122 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:
       
   123 .LP
       
   124 .RS 3
       
   125 
       
   126 .LP
       
   127 .nf
       
   128 \f3
       
   129 .fl
       
   130 % jar cmf myManifestFile myFile.jar *.class
       
   131 .fl
       
   132 \fP
       
   133 .fi
       
   134 .RE
       
   135 
       
   136 .LP
       
   137 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.
       
   138 .br
       
   139 
       
   140 .LP
       
   141 .br
       
   142 
       
   143 .LP
       
   144 \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: 
       
   145 .RS 3
       
   146 
       
   147 .LP
       
   148 .nf
       
   149 \f3
       
   150 .fl
       
   151 % jar cfm myFile.jar myManifestFile *.class
       
   152 .fl
       
   153 \fP
       
   154 .fi
       
   155 .RE
       
   156 
       
   157 .LP
       
   158 The manifest is in a text format inspired by RFC822 ASCII format, so it is easy to view and process manifest\-file contents. 
       
   159 .LP
       
   160 To extract the files from a jar file, use \f2x\fP:
       
   161 .LP
       
   162 .RS 3
       
   163 
       
   164 .LP
       
   165 .nf
       
   166 \f3
       
   167 .fl
       
   168 % jar xf myFile.jar
       
   169 .fl
       
   170 \fP
       
   171 .fi
       
   172 .RE
       
   173 
       
   174 .LP
       
   175 .LP
       
   176 To extract individual files from a jar file, supply their filenames:
       
   177 .LP
       
   178 .RS 3
       
   179 
       
   180 .LP
       
   181 .nf
       
   182 \f3
       
   183 .fl
       
   184 % jar xf myFile.jar foo bar
       
   185 .fl
       
   186 \fP
       
   187 .fi
       
   188 .RE
       
   189 
       
   190 .LP
       
   191 .LP
       
   192 Beginning with version 1.3 of the Java 2 SDK, the \f2jar\fP utility supports 
       
   193 .na
       
   194 \f2JarIndex\fP @
       
   195 .fi
       
   196 http://ccc.sfbay/guide/jar/jar.html#JAR%20Index, 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.
       
   197 .LP
       
   198 .RS 3
       
   199 
       
   200 .LP
       
   201 .nf
       
   202 \f3
       
   203 .fl
       
   204 % jar i main.jar
       
   205 .fl
       
   206 \fP
       
   207 .fi
       
   208 .RE
       
   209 
       
   210 .LP
       
   211 .LP
       
   212 In this example, an \f2INDEX.LIST\fP file is inserted into the \f2META\-INF\fP directory of \f2main.jar\fP.
       
   213 .br
       
   214 .br
       
   215 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.
       
   216 .br
       
   217 .br
       
   218 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):
       
   219 .LP
       
   220 .RS 3
       
   221 
       
   222 .LP
       
   223 .nf
       
   224 \f3
       
   225 .fl
       
   226 % (cd dir1; jar c .) | (cd dir2; jar x)
       
   227 .fl
       
   228 \fP
       
   229 .fi
       
   230 .RE
       
   231 
       
   232 .LP
       
   233 .LP
       
   234 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 
       
   235 .na
       
   236 \f2Java Tutorial\fP @
       
   237 .fi
       
   238 http://java.sun.com/docs/books/tutorial/jar.
       
   239 .LP
       
   240 .SH "OPTIONS"
       
   241 .LP
       
   242 
       
   243 .LP
       
   244 .TP 3
       
   245 c 
       
   246 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. 
       
   247 .TP 3
       
   248 u 
       
   249 Updates an existing file \f2jarfile\fP (when \f2f\fP is specified) by adding to it files and directories specified by \f2inputfiles\fP. For example: 
       
   250 .RS 3
       
   251 
       
   252 .LP
       
   253 .nf
       
   254 \f3
       
   255 .fl
       
   256 jar uf foo.jar foo.class
       
   257 .fl
       
   258 \fP
       
   259 .fi
       
   260 .RE
       
   261 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: 
       
   262 .RS 3
       
   263 
       
   264 .LP
       
   265 .nf
       
   266 \f3
       
   267 .fl
       
   268 jar umf manifest foo.jar
       
   269 .fl
       
   270 \fP
       
   271 .fi
       
   272 .RE
       
   273 updates the \f2foo.jar\fP manifest with the \f2name : value\fP pairs in \f2manifest\fP. 
       
   274 .TP 3
       
   275 x 
       
   276 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. 
       
   277 .TP 3
       
   278 t 
       
   279 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. 
       
   280 .TP 3
       
   281 i 
       
   282 Generate index information for the specified \f2jarfile\fP and its dependent jar files. For example: 
       
   283 .RS 3
       
   284 
       
   285 .LP
       
   286 .nf
       
   287 \f3
       
   288 .fl
       
   289 jar i foo.jar
       
   290 .fl
       
   291 \fP
       
   292 .fi
       
   293 .RE
       
   294 .LP
       
   295 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.   
       
   296 .TP 3
       
   297 f 
       
   298 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). 
       
   299 .TP 3
       
   300 v 
       
   301 Generates verbose output to standard output. Examples shown below. 
       
   302 .TP 3
       
   303 0 
       
   304 (zero) Store without using ZIP compression. 
       
   305 .TP 3
       
   306 M 
       
   307 Do not create a manifest file entry (for c and u), or delete a manifest file entry if one exists (for u). 
       
   308 .TP 3
       
   309 m 
       
   310 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. 
       
   311 .LP
       
   312 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: 
       
   313 .RS 3
       
   314 
       
   315 .LP
       
   316 .nf
       
   317 \f3
       
   318 .fl
       
   319 jar cmf myManifestFile myFile.jar *.class
       
   320 .fl
       
   321 \fP
       
   322 .fi
       
   323 .RE
       
   324 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 
       
   325 .na
       
   326 \f2JAR Files\fP @
       
   327 .fi
       
   328 http://java.sun.com/docs/books/tutorial/jar/ trail in the Java Tutorial  for examples of using the \f4\-m\fP option. 
       
   329 .TP 3
       
   330 e 
       
   331 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.
       
   332 .br
       
   333 .br
       
   334 For example, this command creates \f2Main.jar\fP where the \f2Main\-Class\fP attribute value in the manifest is set to \f2Main\fP: 
       
   335 .RS 3
       
   336 
       
   337 .LP
       
   338 .nf
       
   339 \f3
       
   340 .fl
       
   341 jar cfe Main.jar Main Main.class
       
   342 .fl
       
   343 \fP
       
   344 .fi
       
   345 .RE
       
   346 .LP
       
   347 The java runtime can directly invoke this application by running the following command: 
       
   348 .RS 3
       
   349 
       
   350 .LP
       
   351 .nf
       
   352 \f3
       
   353 .fl
       
   354 java \-jar Main.jar
       
   355 .fl
       
   356 \fP
       
   357 .fi
       
   358 .RE
       
   359 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: 
       
   360 .RS 3
       
   361 
       
   362 .LP
       
   363 .nf
       
   364 \f3
       
   365 .fl
       
   366 jar \-cfe Main.jar foo/Main foo/Main.class
       
   367 .fl
       
   368 \fP
       
   369 .fi
       
   370 .RE
       
   371 or 
       
   372 .RS 3
       
   373 
       
   374 .LP
       
   375 .nf
       
   376 \f3
       
   377 .fl
       
   378 jar \-cfe Main.jar foo.Main foo/Main.class
       
   379 .fl
       
   380 \fP
       
   381 .fi
       
   382 .RE
       
   383 \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. 
       
   384 .LP
       
   385 .TP 3
       
   386 \-C \ dir 
       
   387 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.
       
   388 .br
       
   389 .br
       
   390 For example, this command changes to the \f2classes\fP directory and adds the \f2bar.class\fP from that directory to \f2foo.jar\fP: 
       
   391 .RS 3
       
   392 
       
   393 .LP
       
   394 .nf
       
   395 \f3
       
   396 .fl
       
   397 jar uf foo.jar \-C classes bar.class
       
   398 .fl
       
   399 \fP
       
   400 .fi
       
   401 .RE
       
   402 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. 
       
   403 .RS 3
       
   404 
       
   405 .LP
       
   406 .nf
       
   407 \f3
       
   408 .fl
       
   409 jar uf foo.jar \-C classes . \-C bin xyz.class
       
   410 .fl
       
   411 \fP
       
   412 .fi
       
   413 .RE
       
   414 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: 
       
   415 .RS 3
       
   416 
       
   417 .LP
       
   418 .nf
       
   419 \f3
       
   420 .fl
       
   421 META\-INF/
       
   422 .fl
       
   423 META\-INF/MANIFEST.MF
       
   424 .fl
       
   425 bar1
       
   426 .fl
       
   427 bar2
       
   428 .fl
       
   429 xyz.class
       
   430 .fl
       
   431 \fP
       
   432 .fi
       
   433 .RE
       
   434 .LP
       
   435 .TP 3
       
   436 \-Joption 
       
   437 Pass \f2option\fP to the Java runtime environment, where \f2option\fP is one of the options described on the reference page for the 
       
   438 .na
       
   439 \f2java application launcher\fP @
       
   440 .fi
       
   441 http://ccc.sfbay/4291383/attachment/java.html#options. 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. 
       
   442 .LP
       
   443 .SH "COMMAND LINE ARGUMENT FILES"
       
   444 .LP
       
   445 
       
   446 .LP
       
   447 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. 
       
   448 .LP
       
   449 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.
       
   450 .LP
       
   451 .LP
       
   452 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.
       
   453 .br
       
   454 .br
       
   455 The example below, \f2classes.list\fP holds the names of files output by a \f2find\fP command: 
       
   456 .LP
       
   457 .RS 3
       
   458 
       
   459 .LP
       
   460 .nf
       
   461 \f3
       
   462 .fl
       
   463 % find \fP\f3.\fP \-name '*.class' \-print > classes.list
       
   464 .fl
       
   465 .fi
       
   466 .RE
       
   467 
       
   468 .LP
       
   469 .LP
       
   470 You can then execute the \f2jar\fP command on \f2Classes.list\fP by passing it to \f2jar\fP using argfile syntax:
       
   471 .LP
       
   472 .RS 3
       
   473 
       
   474 .LP
       
   475 .nf
       
   476 \f3
       
   477 .fl
       
   478 % jar cf my.jar @classes.list
       
   479 .fl
       
   480 \fP
       
   481 .fi
       
   482 .RE
       
   483 
       
   484 .LP
       
   485 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: 
       
   486 .RS 3
       
   487 
       
   488 .LP
       
   489 .nf
       
   490 \f3
       
   491 .fl
       
   492 % jar @path1/classes.list
       
   493 .fl
       
   494 \fP
       
   495 .fi
       
   496 .RE
       
   497 
       
   498 .LP
       
   499 .LP
       
   500 
       
   501 .LP
       
   502 .SH "EXAMPLES"
       
   503 .LP
       
   504 
       
   505 .LP
       
   506 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. 
       
   507 .RS 3
       
   508 
       
   509 .LP
       
   510 .nf
       
   511 \f3
       
   512 .fl
       
   513 % ls
       
   514 .fl
       
   515 1.au          Animator.class    monkey.jpg
       
   516 .fl
       
   517 2.au          Wave.class        spacemusic.au
       
   518 .fl
       
   519 3.au          at_work.gif
       
   520 .fl
       
   521 
       
   522 .fl
       
   523 % jar cvf bundle.jar *
       
   524 .fl
       
   525 added manifest
       
   526 .fl
       
   527 adding: 1.au(in = 2324) (out= 67)(deflated 97%)
       
   528 .fl
       
   529 adding: 2.au(in = 6970) (out= 90)(deflated 98%)
       
   530 .fl
       
   531 adding: 3.au(in = 11616) (out= 108)(deflated 99%)
       
   532 .fl
       
   533 adding: Animator.class(in = 2266) (out= 66)(deflated 97%)
       
   534 .fl
       
   535 adding: Wave.class(in = 3778) (out= 81)(deflated 97%)
       
   536 .fl
       
   537 adding: at_work.gif(in = 6621) (out= 89)(deflated 98%)
       
   538 .fl
       
   539 adding: monkey.jpg(in = 7667) (out= 91)(deflated 98%)
       
   540 .fl
       
   541 adding: spacemusic.au(in = 3079) (out= 73)(deflated 97%)
       
   542 .fl
       
   543 \fP
       
   544 .fi
       
   545 .RE
       
   546 
       
   547 .LP
       
   548 If you already have separate subdirectories for images, audio files and classes, you can combine them into a single jar file: 
       
   549 .RS 3
       
   550 
       
   551 .LP
       
   552 .nf
       
   553 \f3
       
   554 .fl
       
   555 % ls \-F
       
   556 .fl
       
   557 audio/ classes/ images/
       
   558 .fl
       
   559 
       
   560 .fl
       
   561 % jar cvf bundle.jar audio classes images
       
   562 .fl
       
   563 added manifest
       
   564 .fl
       
   565 adding: audio/(in = 0) (out= 0)(stored 0%)
       
   566 .fl
       
   567 adding: audio/1.au(in = 2324) (out= 67)(deflated 97%)
       
   568 .fl
       
   569 adding: audio/2.au(in = 6970) (out= 90)(deflated 98%)
       
   570 .fl
       
   571 adding: audio/3.au(in = 11616) (out= 108)(deflated 99%)
       
   572 .fl
       
   573 adding: audio/spacemusic.au(in = 3079) (out= 73)(deflated 97%)
       
   574 .fl
       
   575 adding: classes/(in = 0) (out= 0)(stored 0%)
       
   576 .fl
       
   577 adding: classes/Animator.class(in = 2266) (out= 66)(deflated 97%)
       
   578 .fl
       
   579 adding: classes/Wave.class(in = 3778) (out= 81)(deflated 97%)
       
   580 .fl
       
   581 adding: images/(in = 0) (out= 0)(stored 0%)
       
   582 .fl
       
   583 adding: images/monkey.jpg(in = 7667) (out= 91)(deflated 98%)
       
   584 .fl
       
   585 adding: images/at_work.gif(in = 6621) (out= 89)(deflated 98%)
       
   586 .fl
       
   587 
       
   588 .fl
       
   589 % ls \-F
       
   590 .fl
       
   591 audio/ bundle.jar classes/ images/
       
   592 .fl
       
   593 \fP
       
   594 .fi
       
   595 .RE
       
   596 
       
   597 .LP
       
   598 To see the entry names in the jarfile, use the \f2t\fP option: 
       
   599 .RS 3
       
   600 
       
   601 .LP
       
   602 .nf
       
   603 \f3
       
   604 .fl
       
   605 % jar tf bundle.jar
       
   606 .fl
       
   607 META\-INF/
       
   608 .fl
       
   609 META\-INF/MANIFEST.MF
       
   610 .fl
       
   611 audio/1.au
       
   612 .fl
       
   613 audio/2.au
       
   614 .fl
       
   615 audio/3.au
       
   616 .fl
       
   617 audio/spacemusic.au
       
   618 .fl
       
   619 classes/Animator.class
       
   620 .fl
       
   621 classes/Wave.class
       
   622 .fl
       
   623 images/monkey.jpg
       
   624 .fl
       
   625 images/at_work.gif
       
   626 .fl
       
   627 \fP
       
   628 .fi
       
   629 .RE
       
   630 
       
   631 .LP
       
   632 .LP
       
   633 To add an index file to the jar file for speeding up class loading, use the \f2i\fP option.
       
   634 .br
       
   635 .br
       
   636 Example:
       
   637 .br
       
   638 
       
   639 .LP
       
   640 .RS 3
       
   641 
       
   642 .LP
       
   643 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.
       
   644 .br
       
   645 
       
   646 .LP
       
   647 .br
       
   648 
       
   649 .LP
       
   650 If you specify the \f2Class\-path\fP attribute in the \f2main.jar\fP manifest as: 
       
   651 .nf
       
   652 \f3
       
   653 .fl
       
   654 Class\-Path: buy.jar sell.jar
       
   655 .fl
       
   656 \fP
       
   657 .fi
       
   658 
       
   659 .LP
       
   660 then you can use the \f2\-i\fP option to speed up the class loading time for your application: 
       
   661 .nf
       
   662 \f3
       
   663 .fl
       
   664 % jar i main.jar
       
   665 .fl
       
   666 \fP
       
   667 .fi
       
   668 
       
   669 .LP
       
   670 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.
       
   671 .RE
       
   672 .SH "SEE ALSO"
       
   673 .LP
       
   674 
       
   675 .LP
       
   676 .na
       
   677 \f2The Jar Overview\fP @
       
   678 .fi
       
   679 http://ccc.sfbay/guide/jar/jarGuide.html
       
   680 .br
       
   681 
       
   682 .LP
       
   683 .na
       
   684 \f2The Jar File Specification\fP @
       
   685 .fi
       
   686 http://ccc.sfbay/guide/jar/jar.html
       
   687 .br
       
   688 
       
   689 .LP
       
   690 .na
       
   691 \f2The JarIndex Spec\fP @
       
   692 .fi
       
   693 http://ccc.sfbay/guide/jar/jar.html#JAR%20Index
       
   694 .br
       
   695 
       
   696 .LP
       
   697 .na
       
   698 \f2Jar Tutorial\fP @
       
   699 .fi
       
   700 http://java.sun.com/docs/books/tutorial/jar on the Java Software web site.
       
   701 .br
       
   702 
       
   703 .LP
       
   704 .na
       
   705 \f2pack200 Reference Page\fP @
       
   706 .fi
       
   707 http://ccc.sfbay/4291383/share/pack200.html 
       
   708 .LP
       
   709