jar-The Java Archive Tool
f3jar combines multiple files into a single JAR archive file.
Create jar file f4jar cf2[v0Mmfe] [f2manifestf2] [f2jarfilef2] [f2entrypointf2] [-C f2dirf2] f2inputfiles f2[-Jf2optionf2]
Update jar file f4jar uf2[v0Mmfe] [f2manifestf2] [f2jarfilef2] [f2entrypointf2] [-C f2dirf2] f2inputfiles f2[-Jf2optionf2]
Extract jar file f4jar xf2[vf] [f2jarfilef2] [f2inputfilesf2] [-Jf2optionf2]
List table of contents of jar file f4jar tf2[vf] [f2jarfilef2] [f2inputfilesf2] [-Jf2optionf2]
Add index to jar file f4jar i f2jarfile f2[-Jf2optionf2]
where:
cuxtiv0Mmfe Options that control the f2jar command.
jarfile Jar file to be created (f2c), updated (f2u), extracted (f2x), or have its table of contents viewed (f2t). The f2-f option and filename f2jarfile are a pair -- if either is present, they must both appear. Note that omitting f2f and f2jarfile accepts a "jar file" from standard input (for x and t) or sends the "jar file" to standard output (for c and u).
inputfiles Files or directories, separated by spaces, to be combined into f2jarfile (for c and u), or to be extracted (for x) or listed (for t) from f2jarfile. All directories are processed recursively. The files are compressed unless option f20 (zero) is used.
manifest Pre-existing manifest file whose f2namef2: f2value pairs are to be included in MANIFEST.MF in the jar file. The f2-m option and filename f2manifest are a pair -- if either is present, they must both appear. The letters f3m, f3f and f3e must appear in the same order that f2manifest, f2jarfile, f2entrypoint appear.
entrypoint The name of the class that set as the application entry point for stand-alone applications bundled into executable jar file. The f2-e option and entrypoint are a pair -- if either is present, they must both appear. The letters f3m, f3f and f3e must appear in the same order that f2manifest, f2jarfile, f2entrypoint appear.
-C dir Temporarily changes directories to f2dir while processing the following f2inputfiles argument. Multiple f2-C f2dir f2inputfiles sets are allowed.
-Joption Option to be passed into the Java runtime environment. (There must be no space between f2-J and f2option).
The f3jar tool combines multiple files into a single JAR archive file. f3jar is a general-purpose archiving and compression tool, based on ZIP and the
f2ZLIB @
http://www.gzip.org/zlib/ compression format. However, f3jar 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 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 command. A f3jar archive can be used as a class path entry, whether or not it is compressed.
Typical usage to combine files into a jar file is:
f3 % jar cf myFile.jar *.class
In this example, all the class files in the current directory are placed into the file named f2myFile.jar. The jar tool automatically generates a manifest file entry named f2META-INF/MANIFEST.MF. 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 pairs. Refer to the
f2JAR file specification @
http://docs.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.
If a jar file should include f2name : value pairs contained in an existing manifest file, specify that file using the f2-m option:
f3 % jar cmf myManifestFile myFile.jar *.class
An existing manifest file must end with a new line character. f3jar does not parse the last line of a manifest file if it does not end with a new line character.
f3Note: A jar command that specifies f2cfm on the command line instead of f2cmf (the order of the m and -f options are reversed), the f3jar command line must specify the name of the jar archive first, followed by the name of the manifest file:
f3 % jar cfm myFile.jar myManifestFile *.class
The manifest is in a text format inspired by RFC 822 ASCII format, so it is easy to view and process manifest-file contents.
To extract the files from a jar file, use f2x:
f3 % jar xf myFile.jar
To extract individual files from a jar file, supply their filenames:
f3 % jar xf myFile.jar foo bar
Beginning with version 1.3 of the JDK, the f2jar utility supports
f2JarIndex @
http://docs.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 with the f2-ioption. 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 attribute of the main jar file's manifest.
f3 % jar i main.jar
In this example, an f2INDEX.LIST file is inserted into the f2META-INF directory of f2main.jar.
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 specification.
To copy directories, first compress files in f2dir1 to f2stdout, then extract from f2stdin to f2dir2 (omitting the f2-f option from both f2jar commands):
f3 % (cd dir1; jar c .) | (cd dir2; jar x)
To review command samples which use f2jar to opeate on jar files and jar file manifests, see Examples, below. Also refer to the jar trail of the
f2Java Tutorial @
http://docs.oracle.com/javase/tutorial/deployment/jar/.
c Creates a new archive file named f2jarfile (if f2f is specified) or to standard output (if f2f and f2jarfile are omitted). Add to it the files and directories specified by f2inputfiles.
u Updates an existing file f2jarfile (when f2f is specified) by adding to it files and directories specified by f2inputfiles. For example:
f3 jar uf foo.jar foo.class
would add the file f2foo.class to the existing jar file f2foo.jar. The f2-u option can also update the manifest entry, as given by this example:
f3 jar umf manifest foo.jar
updates the f2foo.jar manifest with the f2name : value pairs in f2manifest.
x Extracts files and directories from f2jarfile (if f2f is specified) or standard input (if f2f and f2jarfile are omitted). If f2inputfiles 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.
t Lists the table of contents from f2jarfile (if f2f is specified) or standard input (if f2f and f2jarfile are omitted). If f2inputfiles is specified, only those specified files and directories are listed. Otherwise, all files and directories are listed.
i Generate index information for the specified f2jarfile and its dependent jar files. For example:
f3 jar i foo.jar
would generate an f2INDEX.LIST file in f2foo.jar which contains location information for each package in f2foo.jar and all the jar files specified in the f2Class-Path attribute of f2foo.jar. See the index example.
f Specifies the file f2jarfile to be created (f2c), updated (f2u), extracted (f2x), indexed (f2i), or viewed (f2t). The f2-f option and filename f2jarfile are a pair -- if present, they must both appear. Omitting f2f and f2jarfile accepts a jar file name from f2stdin(for x and t) or sends jar file to f2stdout (for c and u).
v Generates verbose output to standard output. Examples shown below.
0 (zero) Store without using ZIP compression.
M Do not create a manifest file entry (for c and u), or delete a manifest file entry if one exists (for u).
m Includes f2name : value attribute pairs from the specified manifest file f2manifest in the file at f2META-INF/MANIFEST.MF. f2jar adds a f2name : value pair unless an entry already exists with the same name, in which case f2jar updates its value.
On the command line, the letters f3m and f3f must appear in the same order that f2manifest and f2jarfile appear. Example use:
f3 jar cmf myManifestFile myFile.jar *.class
You can add special-purpose f2name : value 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
f2Packaging Programs in JAR Files @
http://docs.oracle.com/javase/tutorial/deployment/jar/ lesson in the Java Tutorial for examples of using the f4-m option.
e Sets f2entrypoint 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 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.
For example, this command creates f2Main.jar where the f2Main-Class attribute value in the manifest is set to f2Main:
f3 jar cfe Main.jar Main Main.class
The java runtime can directly invoke this application by running the following command:
f3 java -jar Main.jar
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 is in a package called f2foo the entry point can be specified in the following ways:
f3 jar -cfe Main.jar foo/Main foo/Main.class
or
f3 jar -cfe Main.jar foo.Main foo/Main.class
f3Note: specifying both f2-m and f2-e options together when the given manifest also contains the f2Main-Class attribute results in an ambigous f2Main.class specification, leading to an error and the jar creation or update operation is aborted.
-C dir Temporarily changes directories (f2cd f2dir) during execution of the f2jar command while processing the following f2inputfiles argument. Its operation is intended to be similar to the f2-C option of the UNIX f2tar utility.
For example, this command changes to the f2classes directory and adds the f2bar.class from that directory to f2foo.jar:
f3 jar uf foo.jar -C classes bar.class
This command changes to the f2classes directory and adds to f2foo.jar all files within the f2classes directory (without creating a classes directory in the jar file), then changes back to the original directory before changing to the f2bin directory to add f2xyz.class to f2foo.jar.
f3 jar uf foo.jar -C classes . -C bin xyz.class
If f2classes holds files f2bar1 and f2bar2, then here's what the jar file will contain using f2jar tf foo.jar:
f3 META-INF/ META-INF/MANIFEST.MF bar1 bar2 xyz.class
-Joption Pass f2option to the Java runtime environment, where f2option is one of the options described on the reference page for the java application launcher. For example, f4-J-Xmx48M sets the maximum memory to 48 megabytes. It is a common convention for f2-J to pass options to the underlying runtime environment.
To shorten or simplify the jar command line, you can specify one or more files that themselves contain arguments to the f2jar command (except f2-J options). This enables you to create jar commands of any length, overcoming command line limits imposed by the operating system.
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@ character to recursively interpret files is not supported. The f2-J options are not supported because they are passed to the launcher, which does not support argument files.
When executing f2jar, pass in the path and name of each argument file with the f2@ leading character. When f2jar encounters an argument beginning with the character f2@, it expands the contents of that file into the argument list.
The example below, f2classes.list holds the names of files output by a f2find command:
f3 % find f3. -name '*.class' -print > classes.list
You can then execute the f2jar command on f2Classes.list by passing it to f2jar using argfile syntax:
f3 % jar cf my.jar @classes.list
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:
f3 % jar @path1/classes.list
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 option) will tell you more information about the files in the archive, such as their size and last modified date.
f3 % ls 1.au Animator.class monkey.jpg 2.au Wave.class spacemusic.au 3.au at_work.gif % jar cvf bundle.jar * added manifest adding: 1.au(in = 2324) (out= 67)(deflated 97%) adding: 2.au(in = 6970) (out= 90)(deflated 98%) adding: 3.au(in = 11616) (out= 108)(deflated 99%) adding: Animator.class(in = 2266) (out= 66)(deflated 97%) adding: Wave.class(in = 3778) (out= 81)(deflated 97%) adding: at_work.gif(in = 6621) (out= 89)(deflated 98%) adding: monkey.jpg(in = 7667) (out= 91)(deflated 98%) adding: spacemusic.au(in = 3079) (out= 73)(deflated 97%)
If you already have separate subdirectories for images, audio files and classes, you can combine them into a single jar file:
f3 % ls -F audio/ classes/ images/ % jar cvf bundle.jar audio classes images added manifest adding: audio/(in = 0) (out= 0)(stored 0%) adding: audio/1.au(in = 2324) (out= 67)(deflated 97%) adding: audio/2.au(in = 6970) (out= 90)(deflated 98%) adding: audio/3.au(in = 11616) (out= 108)(deflated 99%) adding: audio/spacemusic.au(in = 3079) (out= 73)(deflated 97%) adding: classes/(in = 0) (out= 0)(stored 0%) adding: classes/Animator.class(in = 2266) (out= 66)(deflated 97%) adding: classes/Wave.class(in = 3778) (out= 81)(deflated 97%) adding: images/(in = 0) (out= 0)(stored 0%) adding: images/monkey.jpg(in = 7667) (out= 91)(deflated 98%) adding: images/at_work.gif(in = 6621) (out= 89)(deflated 98%) % ls -F audio/ bundle.jar classes/ images/
To see the entry names in the jarfile, use the f2t option:
f3 % jar tf bundle.jar META-INF/ 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
To add an index file to the jar file for speeding up class loading, use the f2i option.
Example:
If you split the inter-dependent classes for a stock trade application into three jar files: f2main.jar, f2buy.jar, and f2sell.jar.
If you specify the f2Class-path attribute in the f2main.jar manifest as:
f3 Class-Path: buy.jar sell.jar
then you can use the f2-i option to speed up the class loading time for your application:
f3 % jar i main.jar
An f2INDEX.LIST file is inserted to the f2META-INF directory. This enables the application class loader to download the specified jar files when it is searching for classes or resources.
f2The Jar Overview @
http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jarGuide.html
f2The Jar File Specification @
http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html
f2The JarIndex Spec @
http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Index
f2Jar Tutorial @
http://docs.oracle.com/javase/tutorial/deployment/jar/index.html
pack200(1)