Java Archive (JAR) utility

Source: Internet
Author: User
Tags command line documentation zip

The ZIP format is also used in the Java 1.1 jar (Java ARchive) file format. The purpose of this file format is to merge a series of files into a single compressed file, as in zip. However, like anything else in Java, jar files are cross-platform, so there is no need to be concerned about specific platform issues. In addition to including sound and image files, you can include class files in them.
Jar files appear particularly useful when it comes to Internet applications. Before the jar file, the Web browser must repeatedly request the Web server to download all the files that make up a "patch" (applet). In addition, each file is uncompressed. But after merging all of these files into a jar file, simply send a single request to the remote server. At the same time, due to the use of compression technology, so in a shorter period of time to obtain all the data. In addition, each entry (entry) in the jar file can be digitally signed (refer to the Java user documentation for details).
A jar file consists of a series of files in a zip-compressed format, along with a "detail list" that describes all of these files (you can create your own detail file; otherwise, the JAR program will do the same for us). In the online user documentation, you can find more information on the JAR details list (the English for the details is "Manifest").
The Jar utility is available with the sun's JDK and can be automatically compressed as we choose. Please call it at the command line:

jar [Options] description [Detail list] input file

Where options are represented by a series of letters (you do not have to enter a hyphen or any other indicator). As shown below:

C Create a new or empty compressed file
T lists table of contents
X Extract All Files
x file extracts the specified files
F says "I'm going to provide you with the filename." If this argument is omitted, the jar assumes that its input comes from standard input, or that when it creates a file, the output enters the standard output
M indicates that the first parameter will be the user-built details table file name
V produces detailed output and describes the work of the jar in an exhaustive description
O save files only; Do not compress files (for creating a jar file so that we can place it in our own classpath)
M does not automatically generate detail table files

In a file that is ready to enter a jar file, if a subdirectory is included, that subdirectory is automatically added, including all of its own subdirectories, and so on. Path information is also preserved.
Here are some typical ways to invoke jars:

Jar CF Myjarfile.jar *.class
Used to create a jar file named Myjarfile.jar that contains all the class files in the current directory, as well as an automatically generated detail table file.

Jar CMF Myjarfile.jar MYMANIFESTFILE.MF *.class
Similar to the previous one, but added a user-built detail table file named MYMANIFESTFILE.MF.

Jar TF Myjarfile.jar
Generates a table of contents for all files within the Myjarfile.jar.

Jar TVF Myjarfile.jar
Add a "verbose" (detailed) flag to provide more detailed information about the files in Myjarfile.jar.

Jar CVF Myapp.jar Audio classes image
Assuming that audio,classes and image are subdirectories, all subdirectories are merged into the file Myapp.jar. It also includes the "verbose" flag, which allows you to feedback more detailed information as the JAR program works.

If you create a jar file with the O option, that file can be placed in its own classpath (CLASSPATH):
Classpath= "Lib1.jar;lib2.jar;"
Java can search for target class files in Lib1.jar and Lib2.jar.

The functionality of the Jar tool is not as rich as the zip tool. For example, you cannot add or update a file in a ready-made jar file, you can create a new jar file from scratch. In addition, you cannot move files into a jar file and delete them after they are moved. However, jar files created on one platform can be read without hindrance by the jar tool on any other platform (this problem sometimes bothers the zip tool).
As you will see in the 13th chapter, we also use jars to package the Java beans.

Related Article

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.