Jar package-related commands

Source: Internet
Author: User

Recently, the instructor asked me to summarize the relevant knowledge about jar commands, So I integrated a lot of information and made the following summary:

1. Jar Package:  Jar files are Java archive files and are a Java document format. Jar files are very similar to zip files. More accurately, it is a zip file, so it is called a file package. The only difference between a jar file and a zip file is that the content of the JAR file contains a META-INF/manifest. MF file, which is automatically created when the JAR file is generated. 2. Create Jar Package:  Jar packages are classified into executable jar packages and unexecutable jar packages. The difference between them is that the META-INF/manifest. MF file in the jar package specifies whether the main class containing the entry function public static void main (string. As for how to write manifest. MF, we will mention it later. 2.1 Create unexecutable Jar Package: If you create a jar package, it is only used to package your. class bytecode files can be run without double-clicking them, or some files without the main class need to be packaged. class bytecode file, you can create an unexecutable JAR file package. Jar CVF [jar package file name] [package. class file or all. class file folder] Example 2-1: jar CVF test. jar X. class y. after the class is packaged, the jar package contains the META-INF folder, which contains manifest. mf, which is automatically created, and the directory that is the same as the META-INF folder contains the packaged X. class and Y. class. Example 2-2: jar CVF test. after JAR Bao is packaged, the jar package contains the META-INF folder, which contains manifest. mf, which is automatically created, and the Bao folder is included in the same directory as the META-INF folder. 2.2 Create executable Jar Package:  Creating an executable jar package to publish your program is the most typical usage of the jar package. To create an executable JAR file package, use the jar command with the cvfm parameter (this is a common parameter used to create an executable JAR file package. The parameters are described in detail below ), the command format is as follows: jar cvfm [jar package file name] manifest. mf [package. class file or all. class file package] Example 2-3: jar cvfm test. jar manifest. mf x. class y. the directory structure after class packaging is the same as 2.1, but the biggest difference is in the META-INF/manifest of the jar package. mf indicates the main class. Therefore, we need to create our own manifest. MF before packaging. In manifest. the write format in Mf is as follows (assume that X. class main class): Main-class: The full name of the executable main class (including the package name) <press enter> example: Main-class: x <carriage return> Note:: The Key to writing in manifest is main-class: Leave a space with the full name of the executable main class (including the package name) and end with an empty line, that is, end with a carriage return. In addition, the created jar package must contain a complete directory structure that corresponds to the Java program package structure. The class specified by main-class must also be a complete class name containing the package path. For example, assume that X. class and Y. class is in the Bao package, and X. class main Class Example 2-4: The command for creating a jar package is: jar cvfm test. jar manifest. mf Bao while in manifest. mf is written as main-class: Bao. after x <carriage return> is packaged, the jar package contains the META-INF folder, which contains manifest. mf, which is automatically created, and the Bao package is included in the same directory as the META-INF folder. Run the executable jar package. You can double-click the jar package, enter Java-jar [jar package to be run] in the command line, or create. the bar batch file is edited as a Java-jar [JAR file package to be run], which is placed in the same directory as the jar folder and can be run by double-clicking the file. 3. Jar Command details   Jar Command usage:Jar {ctxu} [vfm0m] [Jar-file] [manifest-file] [-C Directory] File Name... {ctxu} is a sub-command of the jar command. Each jar command can contain only one of the ctxu commands, which indicate: -CCreate a new jar package -TList the contents of a jar package -XExpand the specified or all files in the jar package. -UUpdate an existing jar package (add the file to the jar package) [Vfm0m] Options can be selected or not selected. They are jar Command Option Parameters   -VGenerate detailed reports and print them to standard output -FSpecify the JAR file name. This parameter is usually required. -MManifest list file to be included -0Only storage, no compression, the generated JAR file package will be larger than the volume generated without this parameter, but the speed is faster -MDoes not generate the manifest file for all items. This parameter ignores the-M parameter. [Jar- File]A jar package that needs to be generated, viewed, updated, or unlocked. It is a subsidiary parameter of the-F parameter. [Manifest- File]That is, the manifest configuration file, which is a subsidiary parameter of the-M Parameter [-C Directory]The jar command is executed in the specified directory. It is equivalent to converting to this directory using the CD command and then executing the jar command without the-C parameter. It can only be used when creating and updating the JAR file package. The following examples illustrate how to use the main and common jar commands: Example 3-1: Jar CF test. Jar Bao the command does not print the compression execution process. The result is that the test. jar file is generated in the current directory. And the jar package contains the META-INF folder, which has manifest. MF, which are created automatically, and the Bao folder contains the same directory as the META-INF folder. Example 3-2 :Jar CVF test. Jar BAO: The command returns the same result as the preceding command. However, the packaging process is displayed due to the V parameter. Example 3-3 :Jar cvfm test. Jar BAO this command is similar to the result of Example 3-2, but in the generated test. jar does not contain the META-INF/manifest file, there is also the execution process of printing out the compression. Example 3-4 :Jar cvfm test. Jar manifest. MF Bao running result is similar to the example 3-2, print information is the same, but the META-INF/manifest content in the jar package is generated is different, contains manifest. MF content Example 3-5 :Jar TF test. Jar already exists in test. jar, you can view the content in test. jar, the result is as follows: META-INF/manifest. mfbao/X. Class Example 3-6 :Jar tvf test. in addition to the content shown in Example 3-5, Jar also contains the details of the files in the package, such: 0 Fri May 19 15:39:06 GMT 2010 META-INF/86 Fri May 19 15:39:06 GMT 2010 META-INF/manifest. mf 0 Fri May 19 15:39:06 GMT 2010 BaO/7 Fri May 19 15:39:06 GMT 2010 BaO/X. class Example 3-7 :Jar XF test. Jar decompress test. jar to the current directory without printing any information. Example 3-8 :Jar xvf test. Jar decompress test. jar to the current directory and print the detailed information about the decompression process. Example 3-9 :Jar UF test. Jar Y. Class added the file Y. class to test. jar. Example 3-10 :Jar UVF test. Jar Y. Class and Example 3-9 have the same results and detailed information is displayed.

 

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.