Jar-Java archiving Tool

Source: Internet
Author: User
Jar-Java archiving Tool

Merge multiple files into a single JAR file.

Structure
jar [ options ] [manifest] destination input-file [input-files]
Description

The jar tool is a Java application that combines multiple files into a single jar archive file.JarIs a versatile archive and compression Tool Based on Zip and zlib compression formats. However, designJarJava applet or application package into a single archive file. Add the applet or application component (. when the class files, images, and sounds are merged into a single archive file, you can use a Java proxy (such as a browser) to download them during an HTTP transaction process, instead of requiring a new connection for each component. This greatly shortens the download time.JarFiles can be compressed to further increase the download speed. In addition, it allows the author of the applet to sign each item in the file and authenticate its source. The syntax of the jar tool is basicallytarThe command syntax is the same.

The tool is a Java application that combines multiple files into a single jar archive file.JarIs a versatile archive and compression Tool Based on Zip and zlib compression formats. However, designJarJava applet or application package into a single archive file. Add the applet or application component (. when the class files, images, and sounds are merged into a single archive file, you can use a Java proxy (such as a browser) to download them during an HTTP transaction process, instead of requiring a new connection for each component. This greatly shortens the download time.JarFiles can be compressed to further increase the download speed. In addition, it allows the author of the applet to sign each item in the file and authenticate its source. The syntax of the jar tool is basicallytarThe command syntax is the same.

Jar tool input files are divided into three types:

  • Configuration file (optional)
  • Target JAR File
  • Files to be archived

The common usage is:

% jar cf myjarfile *.class

In this example, all class files in the current directory are placed in the file named "myjarfile. The configuration file is automatically generated by the jar tool and is always the first item in the jar file. By default it is named META-INF/manifest. MF. A list file stores metadata related to archiving. For more information about how to store metadata in a configuration file, see configuration specifications.

If you already have a configuration file and want the jar tool to use it for the new jar archive, you can use the-M option to specify it:

% jar cmf myManifestFile myJarFile *.class

The configuration uses the rfc822 ASCII format, so it is easy to view and process the content of the "configuration file.


Option


c
Create a new archive or empty archive on the standard output.
t
List the content table on the standard output.
 
xFile
Extract all files from the standard input, or extract only the specified files. If file is omitted, all files are extracted; otherwise, only the specified files are extracted.
 
f
The second parameter specifies the JAR file to be processed. In cThe second parameter indicates the name of the JAR file to be created (not on the standard output ). In t(Table) or xIn both cases, the second parameter specifies the JAR file to be listed or extracted.
 
v
Output results in the growth format on the output device with a standard error.
 
m
Includes the configuration information in the specified existing configuration file. Example:
jar cmf myManifestFile myJarFile *.class
0
Store only, without zip compression.
 
M
Do not create a project inventory file.
 
u
Update existing jar files by adding files or changing the list. For example:
jar -uf foo.jar foo.class

Change the fileFoo. ClassAdd to existing jar filesFoo. JarAnd

jar umf manifest foo.jar

UseManifestInformation updates inFoo. Jar.

-C
In execution JarChange the directory during the command. For example:
jar -uf foo.jar -C classes *

SetClassesAdd all files in the directoryFoo. JarBut does not add the class directory itself.

If you have“files”Is a directory, the directory will be recursively processed.

Example

Add all files in a specific directory to the archive file:

$ ls0.au            3.au            6.au            9.au            at_work.gif1.au            4.au            7.au            Animator.class  monkey.jpg2.au            5.au            8.au            Wave.class      spacemusic.au$ jar cvf bundle.jar *adding: 0.auadding: 1.auadding: 2.auadding: 3.auadding: 4.auadding: 5.auadding: 6.auadding: 7.auadding: 8.auadding: 9.auadding: Animator.classadding: Wave.classadding: at_work.gifadding: monkey.jpgadding: spacemusic.au$

If your HTML directory contains subdirectories of images, audio files, and classes, you can archive each directory to a single JAR file:

$ lsaudio classes images$ jar cvf bundle.jar audio classes imagesadding: audio/1.auadding: audio/2.auadding: audio/3.auadding: audio/spacemusic.auadding: classes/Animator.classadding: classes/Wave.classadding: images/monkey.jpgadding: images/at_work.gif$ ls -ltotal 142drwxr-xr-x   2 brown    green        512 Aug  1 22:33 audio-rw-r--r--   1 brown    green      68677 Aug  1 22:36 bundle.jardrwxr-xr-x   2 brown    green        512 Aug  1 22:26 classesdrwxr-xr-x   2 brown    green        512 Aug  1 22:25 images$

Then, you can use the jar tool and the "T" option to view the item name in jarfile:

$ lsaudio bundle.jar classes images$ jar tf bundle.jarMETA-INF/MANIFEST.MFaudio/1.auaudio/2.auaudio/3.auaudio/spacemusic.auclasses/Animator.classclasses/Wave.classimages/monkey.jpgimages/at_work.gif$

Listing in long format (using the "v" option) will display more detailed information about each file in the archive file, such as the size of each file and the last modification time:

$ 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$

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.