[Android Pro] Advanced Java Learning: Jar Packaging

Source: Internet
Author: User

Have you ever heard of jar files? or unfamiliar! OK, that's okay, this is our first stop: packing and publishing.

Why do you have this thing, first of all, this is the full name of the jar: JavaTM Archive (jar) file, yes, is the Java archive file. It's a bit like a zip file, think about what it's used for, compression!? Right is to compress, put our original scattered things to a bit, reorganize, all these purposes only one: convenient! Well, don't worry about how he compresses it, our focus is on what we want to compress (input), and what it compresses (the output), and then publish (deploy) it.

Our input (something to compress) is primarily a class file, as well as auxiliary resources (which may have images, JSP files, HTML files, etc.). Jar technology already exists in the jdk1.1 version and has been enhanced in 1.2. Let's talk about the benefits of jar, which is the official description: Secure, fast download, compress, Hunt package, version pack, portable.

Having said so much, we are now beginning to implement.

Open a command prompt (Win2000 or execute the cmd command in the Run box, Win98 the DOS prompt), enter the jar Chelp, and then return (if you already have jdk1.1 or above on the disk) and see what:

Usage: jar {ctxu}[vfm0mi] [jar-file] [manifest-file] [-C directory] File name ...

Options:

-C Create a new archive

-t lists the list of archived content

-X expands the named (or all) file in the archive

-U updates an existing archive

-V generates verbose output on standard output

-f Specifies the archive file name

-M contains marked information from the indicated file

-0 storage mode; Zip compression format not used

-M does not produce a list of all items (manifest) file

-I generates index information for the specified jar file

-C changes to the specified directory and contains the following files:

If a file name is a directory, it will be processed recursively.

The manifest (both the Manifest) file name and the archive file name need to be specified, in the same order specified by the ' m ' and ' F ' flags.

Example 1: Archive two class files into an archive file named ' Classes.jar ':

Jar CVF Classes.jar Foo. class Bar. class  

Example 2: Archive all files under the foo/directory to an archive file named ' Classes.jar ' with an existing manifest (manifest) file ' mymanifest ':

- C - C
Jar CVF ${basedir}/plugin.jar-  c ${basedir} com-  C ${basedir} assets  

Basic jar Operation:

1. Create a JAR file

Jar CF Jar-file Input-file (s)
c---Want to Create a JAR file.
f---want the output to go to a file rather than to stdout.
EG:1) jar CF Myjar.jar Query_maintain_insert.htm
2) jar CVF Myjar.jar query_maintain_insert.htm
V---produces verbose (verbose) output.
3) Jar CVF Myjar.jar query_maintain_insert.htm mydirectory
4) Jar cv0f Myjar.jar query_maintain_insert.htm mydirectory
0---don ' t want the JAR file to be compressed.
5) Jar CMF MANIFEST. MF Myjar.jar Yahh.txt
M---used to include manifest information from an existing manifest file.
6) Jar CMf MANIFEST. MF Myjar.jar Yahh.txt
M---The default manifest file should not being produced.
7) jar CVF Myjar.jar *
*---Create all contents in current directory.

2. View the jar file

Jar TF Jar-file
T---Want to view the Table of contents of the JAR file.
eg:1) jar Vft Yahh.jar
V---produces verbose (verbose) output.

3. Extracting the Jar file

Jar XF Jar-file [Archived-file (s)]
X---Want to extract files from the JAR archive.
eg:1) Jar XF Yahh.jar yahh.txt (extract files Yahh.txt only)

2) Jar XF Yahh.jar Alex/yahhalex.txt (extract only the directory Alex file yahhalex.txt)

3) Jar XF Yahh.jar (extract all files or directories in the jar package)

4. Modify the manifest file

Jar CMF manifest-addition jar-file input-file (s)
M---used to include manifest information from an existing manifest file.

5. Update the JAR file

Jar UF Jar-file input-file (s)
U---Want to update an existing JAR file.

[Android Pro] Advanced Java Learning: Jar Packaging

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.