JAR FILES
1. A QUICK GUIDE
1.1 What is a JAR file?
A JAR (Java ARchive) file is a file where a number of directories and isolated files are stored in a condensed form. |
JAR files are usually given the .jar extension, but this is not necessary. |
Condensed files are in a zip format. A JAR file can be unzipped using an unzipping software. But this is not necessary, since the JAVA system has the jar command to handle them, one option of which unzips them. |
Also, many processors such as the Java Machine, or browsers can directly use the files in a JAR without first extracting the files. |
1.2 Samples
Operations on jar files can be performed using the jar command from the so called DOS command line. Here are the most usual operations:Operation  | Example |
create | jar cfv my_archiv.jar YinYang.class Sphere.class Abc.class creates JAR file 'my_archiv.jar' to store files 'YinYang.class', 'Sphere.class', 'Abc.class' which are in the current directory -- the 'my_archiv.jar' file is created in the same directory |
jar cfv my_archiv.jar -C ../demo xyza create JAR file 'my_archiv.jar' to store directory 'xyza' and all its files -- 'xyza' is in the 'demo' directory whose relative URI based on the current directory is ' ../demo ' -- note that instead of '../demo ' using the slash character, '..\demo ' with the back-slash can also be used.
|
|
update | jar uvf my_archiv.jar Abc.gif Def.jpg add files 'Abc.gif' and 'Def.jpg' which are in the current directory to the content of JAR file 'my_archiv.jar' which is in the same directory |
display | jar tf my_archiv.jar displays the content of JAR file 'my_archiv.jar' which is in the current directory |
extract | All of the filesjar xfv my_archiv.jar extracts all of the files and directories in the 'my_archiv.jar' file, which is in the current directory, and put the extracted files and directories in the current directory |
A list of files (known to be in the jar)jar xf my_archiv.jar xyza/YinYang.class xyza/Xyz.class xyza/Abc.class extracts files 'YinYang.class', 'Xyz.class' and 'Abc.class' contained in directory 'xyza' contained in the 'my_archiv.jar' file, which is in the current directory, and put the extracted files in an 'xyza' directory created in the current directory. |
In the foregoing table, characters in blue are part of the jar code, characters in black are user's.
2. GENERAL SYNTAX
The general form of a JAR command is:
jar {ctxu}[fmv0M] [jar-file] [manifest-file] [-C path] file ...
Characters in red are part of the code, to be written as is. Characters in black are user defined.
jar | is the command code | |
{ctxu} | one of the letters c, t, x or u is to be selected, each representing one of the functions of the jar command: | |
c | creation the command creates a JAR file | |
t | display the command displays the content of a JAR file | |
x | extract the command extracts all of the files contained in the JAR file, or a list of files thereof | |
u | update the command adds files to an existing JAR file | |
[fmv0M] | one or more of the characters f, m, v, 0 or M is to be selected; each represents one of the parameters associated with the function defined by the first choice; these characters are appended to the function character, without intervening space. | |
f | a jar-file name is specified | |
m | a manifest-file name is specified -- the manifest file contains information on the operation performed as a result of submitting the jar command; if a name is not specified, a default manifest file is created -- not all applications need to use the manifest file | |
v | a verbose report on the operations is written out to the standard output file | |
0 | store only -- the files are to be stored in the JAR files without being compressed | |
M | no manifest file is to be created | |
[jar-file> | name of the JAR file; present if and only if the f option above is taken; the JAR file and the manifest file, if both present, must be in the same order as the 'f' and 'm' letters in the option field | |
[manifest-file] | name of the manifest file that provides manifest information to the operation; present if and only if the m option above is taken; the manifest file and the JAR file, if both present, must be in the same order as the 'm' and 'f' letters in the option field. Example:jar cfmv my_archive.jar manifest.mf -C ../java/xyz applet_dir
| |
[-C path] | the two characters sequence -C (capital C) signals that path information follows; path is the URI of the directory that contains the file or directory named in the following (the URI is also called the directory path in this special instance). Examples: | |
jar cfv jarfile.jar -C abc/def Calculus.class the -C sequence signals that the information thats follows, abc/def , is a URI or path information that locates the directory (def) that contains the Calculus.class file.
| ||
jar cfv jarfile.jar -C abc/def ghi .the -C sequence signals that the information thats follows, abc/def , is a URI or path information that locates the directory (def) that contains the ghi directory | ||
file ... | list of one or more files or directories to be stored in, added to or extracted from the JAR file; when a directory is named, that directory and all of its files and subdirectories are stored in, added to or extracted from the JAR file. N.B. There can be more than one element in the list of files or directories to store, add or extract only if the -C option is not used (i.e. the elements are all in the current directory); when the -C option is used, only the first element (file or directory) appearing after the path information is recognized. |