11:48 AM The 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. Format 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. jarfile inputfiles manifest
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. Examples: 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. OPTIONS 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 |
|
Related blogs
You may also like to see:
[2014-01-09] | [Open System-Linux] |
How to send a mail using unix/linux terminal? |
[2014-03-17] | [Open System-Linux] |
AWK command for scanning and analysing a large file in Linux |
[2015-01-18] | [Open System-Linux] |
The JAR archiving tool in Linux |
[2017-08-22] | [Open System-Linux] |
Difference between tailf and tail -f in Linux |
[2015-04-23] | [Open System-Linux] |
15 Great DATE command examples |
Total comments: 0 | |