Java-Unpacking and packaging jars

Source: Internet
Author: User

Unpacking and packaging jars
This address: Http://blog.csdn.net/caroline_wendy
Introduction 1. Compress the package :jar CVF Filename.jar a.class b.class: compresses the specified file;jar CVF Weibosdkcore.jar *: all compression;
2. Unpack the package :jar XVF Test.jar
detailedthe jar command has the function of generating, viewing, updating, and unlocking the jar package.contains meta-inf/manifest. MF file. It is created automatically when the jar package is generated, and is primarily responsible for specifying the main file location and current folder of the jar package. the parameters of the jar command are detailed:
C:\>jar CF Lm.jar
The ' C ' flag requires specifying a list or input file! Usage:
jar {Ctxui}[vfm0me] [jar-file] [manifest-file] [entry-point] [-c dir] files ...
options include:-C Create a new archive file- t lists the archive directory- x Unzip the archived specified (or all) files-U Update existing archive file- v generates verbose output in standard output- f Specifies the archive file name-M contains inventory information from the specified manifest file-E is a standalone application bundled into an executable jar fileSpecify the application entry point0 store only; do not use any ZIP compression-M does not create an entry for the manifest file-I generate index information for the specified jar file- c changes to the specified directory and contains the files thereinIf there is any catalog file, it is recursively processed. the specified order of manifest file names, archive file names, and entry names is the same as the specified order for the "M", "F", and "E" flags.
Example 1archive Two class files into an archive named Classes.jar:
Jar CVF Classes.jar Foo.class bar.class

Example 2use the existing manifest file "Mymanifest" andArchive All files in the foo/directory to "Classes.jar":
Jar CVFM Classes.jar mymanifest-c foo/.

Example 3The Lm.jar package for the executable Jar File type was created under the C drive.
C:\>jar CF Lm.jar Lm.class Lm.java

Example 4The add v parameter shows the package detail process:
C:\jar>jar CVF Lm.jar Lm.class

marked list (manifest):added: Lm.class (read in = 410) (write = 283) (compressed 30%)where the C parameter represents the creation of the jar package, the f parameter is the specified jar package file name. To specify the required parameters when using the jar command:-C Create a new archive file- t lists the archive directory- x Unzip the archived specified (or all) files-U Update existing archive file
Example 5to run the newly generated jar package:
C:\>java-jar Lm.jar
Failed to load Main-class manifest attribute fromLm.jaraccording to the English error, it seems that the manifest property of the Lm.jar package failed to read.
Example 6create does not contain meta-inf/manifest. MF file's jar package
C:\jar>jar CVFM Lm1.jar Lm.class
added: Lm.class (read in = 410) (write = 283) (compressed 30%)
Example 7displaying files in a jar package
C:\jar>jar TF Lm.jarmeta-inf/meta-inf/manifest. Mflm.class

Example 8because the M parameter was used when creating the jar package, there was no Meta-inf directory and meta-inf/manifest. MF file
C:\jar>jar TF Lm1.jarLm.class

Example 9Show file and file details for jar packages
C:\jar>jar TVF lm.jar     0 Mon Sep 23:09:34 CST (meta-inf/)    Mon Sep 23:09:34 CST meta-inf/manifes T.MF   410 Mon Sep-22:09:00 CST-Lm.class
These details include the read-in bytes, the time that was read in the jar package, the directory or the file name
Example Tenunpack the jar package into the current directory
C:\jar>jar XF Lm.jar
does not display any information, but the decompression is successful

Java-Unpacking and packaging jars

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.