"Go" learning jar command Creating and decompression jar packages

Source: Internet
Author: User

Java programming every day with a lot of jar files, project development in the continuous guidance package, in the busy day of work, put down those complex business implementation, not only want to ask these jar package how to build, the jar package has what unique place and so on.

Originally these commonly seen jar package is generated by the jar command, the Java language for us when installing the JDK, the JDK as we installed in the bin directory, in the Windows system is the Jar.exe program, the Linux system is a jar file.

The jar command has the effect of generating, viewing, updating, or unlocking the jar package. The jar package is similar to other compressed packages, but it contains the meta-inf/manifest. MF file, which is created automatically when the jar package is generated.

The parameters of the jar command are detailed:

The

C:\>jar CF Lm.jar
' C ' flag requires a specified manifest 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  List archive directory
   -X   Unzip an archived specified (or all) file
   -u  Update an existing archive
   -v  generate verbose output in standard output
   -f  Specifies the archive file name
   -m  contains inventory information from the specified manifest file
   -e  For standalone applications bundled into executable jar files
        Specify application entry point
    -0  store only ; Do not use any ZIP compression
   -m  do not create an entry manifest file
   -i  Generate index information for the specified jar file
    -c  changes to the specified directory and contains the file
if there is any directory file, it is recursively processed.
The specified order of the manifest file name, the archive file name, and the entry name
is the same as the specified order for the "M", "F", and "E" flags.

Example 1: Archive two class files into an archive named Classes.jar:
Jar CVF Classes.jar Foo.class bar.class
Example 2: Use the existing manifest file "Mymanifest" and
Archive all files in the foo/directory to "Classes.jar":
Jar CVFM Classes.jar mymanifest-c foo/.

Example 1.
C:\>jar CF Lm.jar Lm.class Lm.java

Result: The Lm.jar package for the executable Jar file type was created under the C drive.

Example 2. Add a v parameter to display the package details process,

C:\jar>jar CVF Lm.jar Lm.class
Mark List (manifest)
Added: Lm.class (read in = 410) (write = 283) (30% compressed)

Where the C parameter represents the creation of the jar package, the f parameter is the specified jar package file name. When using the Jar command, specify the required parameters and tell him what you want to do. These parameters 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

Example 3. Run the newly generated jar package:

C:\>java-jar Lm.jar
Failed to load Main-class manifest attribute from
Lm.jar

According to the English error, it seems that the manifest property of the Lm.jar package failed to read.

Example 4. Create 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) (30% compressed)

Example 5. displaying files in a jar package

C:\jar>jar TF Lm.jar
meta-inf/
Meta-inf/manifest. Mf
Lm.class

Example 6. The Meta-inf directory and Meta-inf/manifest are not available because the M parameter is used when creating the jar package. MF File

C:\jar>jar TF Lm1.jar

Lm.class

Example 7. displaying file and file details for a jar package


C:\jar>jar TVF Lm.jar
0 Mon Sep 23:09:34 CST meta-inf/
23:09:34 CST-meta-inf/manifest-Mon Sep 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 8. Unpack the jar package into the current directory


C:\jar>jar XF Lm.jar

does not display any information, but the decompression is successful

Under Windows, run the executable jar package

Command Window execution: Java-jar jar Package

Note: Sometimes, under Windows systems, when you double-click a jar package, the jar package is not run and the jar package is decompressed instead. So let the jar package run, you need the command execution.

"Go" learning jar command Creating and decompression jar packages

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.