a jar package is a compressed document that is unique in Java. The format of the storage format is the. zip package.
But unlike the zip package, a meta-inf\manifest is automatically added when the jar is generated. MF file
Command Parameters
jar {c T x u f}[v m e 0 m i][-c directory] File name ...
where {CTXU} These four parameters must be selected first. [v F m e 0 m i] is an optional parameter and the file name is also required.
- C Create a jar package
-T displays a list of contents in the Jar
- x Decompression jar Package
- u Add file to jar package
-f Specifies the file name of the jar package
- v generates detailed reporting and outputs to standard equipment
-m Specifies the MANIFEST.MF file. (The jar package and its contents can be set in a MANIFEST.MF file)
-0 does not compress the contents of a jar package when it is generated
- M does not produce a manifest file (MANIFEST.MF) for all files. This parameter is set with the Ignore-m parameter
-I create an index file for the specified jar file
-C means go to the appropriate directory to execute the JAR command, equivalent to the CD to that directory, and then execute the JAR command without the-c
using the example
(1) Create a jar package
jar CF Hello.jar File1 file2
The Hello.jar is created, and the file1,file2 (Jar command can specify multiple files) is added to the Hello.jar package, which is overwritten if Hello.jar exists.
The format of the jar package after creation is as follows
Hello.jar
├meta-inf
│└manifest. MF
├file1
└file2
(2) Create and display the packaging process
jar CVF Hello.jar test
The output is as follows (different operating system output may be slightly different)
Added Inventory
: test/(input = 0) (output = 0) (0 stored)
adding: test/(output = 0) (output = 0) (0 stored)
adding: test/test1.class (output = 1497) (output = 818) (compressed 45%)
adding: test/test2class (output = 1344) (output = 736) (compressed 45%)
(3) show jar package
jar TVF Hello.jar
View the contents of the Hello.jar package
If the jar package does not exist, it throws Java.io.FileNotFoundException
If the jar package is malformed (not in zip format), it throws Java.util.zip.ZipException
(4) Unpacking the jar package
jar XVF Hello.jar
unzip Hello.jar to current directory
(5) Add File in Jar
jar UF Hello.jar Helloworld.java
add Helloworld.java to the Hello.jar package
(6) Create an uncompressed content jar package
jar cvf0 Hello.jar *.class
generates an uncompressed jar package using all the. class files in the current directory
(7) Create a jar package (specified MANIFEST.MF file)
jar CVFM Hello.jar manifest.mf file1
when the jar package is created, the specified meta-inf/manifest is used. MF file
(8) Ignore MANIFEST.MF file
jar CVFM Hello.jar test
the generated jar package does not include the Meta-inf directory and the MANIFEST.MF file
(9) Add-C application:
jar CVFM Hello.jar mymanifest.mf-c temp/
represents a switch to the TEMP directory before executing the jar command
(Ten) Jar file build index list
jar I Hello.jar
an index file named Index.list is generated under the Meta-inf folder of the Hello.jar package.
Common jar commands and