'\" t .\" @(#)jar.1 1.3 98/11/10 SMI; .\" Copyright 1999 Sun Microsystems, Inc. All rights reserved. .\" Copyright 1999 Sun Microsystems, Inc. Tous droits r\351serv\351s. .\" ` '\"macro stdmacro .TH jar 1 "18 Feb 1999" .SH NAME jar \- Java archive tool .\" .\" This document was created by saving an HTML file as text .\" from the JavaSoft web site: .\" .\" http://java.sun.com/products/jdk/1.2/docs/tooldocs/tools.html .\" .\" and adding appropriate troff macros. Because the JavaSoft web site .\" man pages can change without notice, it may be helpful to diff .\" files to identify changes other than new functionality. .\" .SH SYNOPSIS .B jar [ .B C ] [ .B c ] [ .B f ] [ .B M ] [ .B m ] [ .B O ] [ .B t ] [ .B u ] [ .B v ] .if n.ti +5n [ .BI x " file" ] [ .I manifest-file ] .if t.ti +5n .I destination input-file .if n.ti +5n [ .I input-files ] .SH DESCRIPTION .IX "Java archive tool" "" "Java archive tool \(em \fLjar\fP" .IX "jar" "" "\fLjar\fP \(em Java archive tool" The .B jar tool is a Java\(tm application that combines multiple files into a single JAR archive file. It is also a general-purpose archiving and compression tool, based on ZIP and the ZLIB compression format. However, .B jar was designed mainly to facilitate the packaging of Java applets or applications into a single archive. When the components of an applet or application (.class files, images and sounds) are combined into a single archive, they may be downloaded by a Java agent (like a browser) in a single HTTP transaction, rather than require a new connection for each piece. This dramatically improves download time. The .B jar tool 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 .B jar tool is almost identical to the syntax for the .BR tar (1) command. .LP The three types of input files for the .B jar tool are: .LP .RS 5 .TP 2 \(bu manifest file (optional) .TP 2 \(bu destination \f3jar\fP file .TP 2 \(bu files to be archived .LP .RE Typical usage is: .LP .RS 5 .B example% jar cf myjarfile *.class .RE .LP In this example, all the class files in the current directory are placed in the file named "myjarfile". A manifest file is automatically generated by the .B jar tool and is always the first entry in the .B jar file. By default, it is named META-INF/MANIFEST.MF. The manifest file is the place where any meta-information about the archive is stored. Refer to the .I Manifest Format in the .B SEE ALSO section for details about how meta-information is stored in the manifest file. .LP To use a pre-existing manifest file to create a new .B jar archive, specify the old manifest file with the .B m option: .LP .RS 5 .B example% jar cmf myManifestFile myJarFile *.class .RE .LP Note that when you specify .B cfm instead of .B cmf (that is, you invert the order of the .B m and .B f options), you need to specify the name of the .SM jar archive first, followed by the name of the manifest file: .LP .RS 5 .B example% jar cfm myJarFile myManifestFile *.class .RE .LP The manifest uses RFC822 ascii format, so it is easy to view and process manifest-file contents. .SH OPTIONS .TP 15 .B C Changes directories during execution of .B jar command. For example .RS .LP .B example% jar -uf foo.jar -C classes * .RE .TP 15 .B c Creates a new or empty archive on the standard output. .TP 15 .B f The second argument specifies a .B jar file to process. In the case of creation, this refers to the name of the .B jar file to be created (instead of on .BR stdout ). For table or xtract, the second argument identifies the .B jar file to be listed or extracted. .TP 15 .B M Do not create a manifest file for the entries. .TP 15 .B m Includes manifest information from specified pre-existing manifest file. Example use: .LP .RS 15 .nf .ft 3 example% jar cmf myManifestFile myJarFile *.class .fi .ft 1 .LP You can add special-purpose name-value attribute headers to the manifest file that aren't contained in the default manifest. Examples of such headers would be those for vendor information, version information, package sealing, and headers to make JAR-bundled applications executable. See the .I JAR Files trail in the .I Java Tutorial and the .I JRE Notes for Developers web page for examples of using the .B m option. .RE .TP 15 .B O Store only, without using ZIP compression. (Use this option to create an archive you can use as a class path entry.) .TP 15 .B t Lists the table of contents from standard output. .TP 15 .B u Update an existing JAR file by adding files or changing the manifest. For example .LP .RS 15 .B example% jar uf foo.jar foo.class .LP would add the file .B foo.class to the existing JAR file .BR foo.jar , and .LP .B example% jar umf foo.jar .LP would update .BR foo.jar 's manifest with the information in manifest. .RE .TP 15 .B v Generates verbose output on .BR stderr . .TP 15 .BI x " file" Extracts all files, or just the named files, from standard input. If .I file is omitted, then all files are extracted; otherwise, only the specified file or files are extracted. .LP If any of .I files is a directory, then that directory is processed recursively. .SH EXAMPLES To add all of the files in a particular directory to an archive: .RS .\" .LP \f3 .nf example% ls 0.au 3.au 6.au 9.au at_work.gif 1.au 4.au 7.au Animator.class monkey.jpg e.au 5.au 8.au Wave.class spacemusic.au example% jar cvf bundle.jar * adding: 0.au adding: 1.au adding: 2.au adding: 3.au adding: 4.au adding: 5.au adding: 6.au adding: 7.au adding: 8.au adding: 9.au adding: Animator.class adding: Wave.class adding: at_work.gif adding: monkey.jpg adding: spacemusic.au example% \f1 .fi .RE If you already have subdirectories for images, audio files, and classes already exist in an HTML directory, use .B jar to archive each directory to a single .B jar file: .RS \f3 .nf example% ls audio classes images example% jar cvf bundle.jar audio classes images adding: audio/1.au adding: audio/2.au adding: audio/3.au adding: audio/spacemusic.au adding: classes/Animator.class adding: classes/Wave.class adding: images/monkey.jpg adding: images/at_work.gif example% ls -l total 142 drwxr-xr-x 2 brown green 512 Aug 1 22:33 audio -rw-r--r-- 1 brown green 68677 Aug 1 22:36 bundle.jar drwxr-xr-x 2 brown green 512 Aug 1 22:26 classes drwxr-xr-x 2 brown green 512 Aug 1 22:25 images example% .fi \f1 .RE To see the entry names in the .B jar file using the .B jar tool and the .B t option: .RS \f3 .nf example% ls audio bundle.jar classes images example% jar tf bundle.jar META-INF/MANIFEST.MF audio/1.au audio/2.au audio/3.au audio/spacemusic.au classes/Animator.class classes/Wave.class images/monkey.jpg images/at_work.gif example% .fi \f1 .RE To display more information about the files, in the archive, such as their size and last modified date, use the .B v option. .RS \f3 .nf example% jar tvf bundle.jar 145 Thu Aug 01 22:27:00 PDT 1996 META-INF/MANIFEST.MF 946 Thu Aug 01 22:24:22 PDT 1996 audio/1.au 1039 Thu Aug 01 22:24:22 PDT 1996 audio/2.au 993 Thu Aug 01 22:24:22 PDT 1996 audio/3.au 48072 Thu Aug 01 22:24:23 PDT 1996 audio/spacemusic.au 16711 Thu Aug 01 22:25:50 PDT 1996 classes/Animator.class 3368 Thu Aug 01 22:26:02 PDT 1996 classes/Wave.class 12809 Thu Aug 01 22:24:48 PDT 1996 images/monkey.jpg 527 Thu Aug 01 22:25:20 PDT 1996 images/at_work.gif example% .fi \f1 .RE .SH ATTRIBUTES See .BR attributes (5) for a description of the following attributes: .sp .TS box; cbp-1 | cbp-1 l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE = Availability SUNWjvdev .TE .SH SEE ALSO .BR keytool (1) .LP .TP 10 \f2JAR Files\fP @ http://java.sun.com/docs/books/tutorial/jar/ .LP .TP 10 \f2JRE Notes\fP @ http://java.sun.com/products/jdk/1.2/runtime.html#example .LP .TP 10 \f2JAR Guide\fP @ http://java.sun.com/products/jdk/1.2/docs/guide/jar/jarGuide.html .LP .TP 10 \f2Manifest Format\fP @ http://java.sun.com/products/jdk/1.2/docs/guide/jar/manifest.html .LP .TP 10 For information on related topics, use the search link @ http://java.sun.com/