11:48 AMThe JAR archiving tool in Linux
JAR, a Java Archive Tool is a command line tool in linux used to combine multiple files into a single JAR archive file.
Update jar file
Extract jar file
List table of contents of jar file
Add index to jar file
where: cuxtiv0Mmfe are the options that control the jar command.
However, jar 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. jar 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 tar command.
1.Combining multiple files into a jar.
% jar cf myFile.jar *.class
In this example, all the class files or all the files (if given *) in the current directory are placed into the file named myjar.jar.
The jar tool automatically generates a manifest file entry named META-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 name : value pairs.
If a jar file should include name : value pairs contained in an existing manifest file, specify that file using the -m option:
% jar cmf myManifestFile myjar.jar *.class
An existing manifest file must end with a new line character. jar does not parse the last line of a manifest file if it does not end
Note: A jar command that specifies cfm on the command line instead of cmf (the order of the m and -f options are reversed), the jar command line must specify the name of the jar archive first, followed by the name of the manifest file:
$ jar cfm myFile.jar myManifestFile *.class
The manifest is in a text format inspired by RFC822 ASCII format, so it is easy to view and process manifest-file contents.
2.To extract the files from a jar file, use x:
% jar xf myFile.jar
3.To extract individual files from a jar file, supply their filenames:
% jar xf myjar.jar Test.java
Beginning with version 1.3 of the Java 2 SDK, the jar utility supports JarIndex @ http://ccc.sfbay/guide/jar/jar.html#JAR%20Index, which allows application class loaders to load classes more efficiently from jar files.
This performance optimization is enabled by running jar with the -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 Class-Path attribute of the main jar files manifest.
$ jar i main.jar
In this example, an INDEX.LIST file is inserted into the META-INF directory of main.jar. The application class loader uses the information stored in this file for efficient class loading.
u Updates an existing file jarfile (when f is specified) by adding to it files and directories specified by inputfiles. For example:
jar uf myjar.jar Test2.class
would add the file Test2.class to the existing jar file foo.jar. See the output of t option below to check that the new file is addded to jar file.
The -u option can also update the manifest entry, as given by this example:
jar umf manifest foo.jar
updates the foo.jar manifest with the name : value pairs in manifest.
x Extracts files and directories from jarfile (if f is specified) or standard input (if f and jarfile are omitted). If inputfiles is
t Lists the table of contents from jarfile (if f is specified) or standard input (if f and jarfile are omitted). If inputfiles is specified, only those specified files and directories are listed. Otherwise, all files and directories are listed.
i Generate index information for the specified jarfile and its dependent jar files. For example:
jar i foo.jar
You may also like to see:
|uptime command in Linux|
|FIND utility in Linux to search for files or directories.|
|md5sum: calculate and check md5 message digest of a file in Linux|
|Addition of two numbers using shell scripting in UNIX|
|Difference between tailf and tail -f in Linux|
|Total comments: 0|