Note that the creation of the JAR file need to include a complete package and the package with the Java program structure of the corresponding directory structure, just like the above example. The Main-Class specified type, it must be complete, including the package path of the class name, as cases test.Test; and JAR files in the absence of labeled packets can be used before the java <class name> to run this type, that is, In the example above java test.Test is running correctly (of course in the case of the correct CLASSPATH).
3. Jar command explain
jar with the JDK is installed in the JDK installation directory under the bin directory, Windows under the file name jar.exe, Linux under the file name jar. It needed to run the JDK installation directory under the lib directory of the tools.jar file. But what we do not need to install the JDK, because SUN has been done to help us. We do not even need to put tools.jar in the CLASSPATH.
Without any use of the jar command jar we can see that the usage of the command is as follows:
jar (ctxu) [vfm0M] [jar-file] [manifest-file] [-C directory] file name ...
(Ctxu) which is a subset of the command jar command, for each jar command can contain only a ctxu They said:
-c create a new JAR package
-t list the contents of JAR file package list
-x to start the specified package JAR file or all files
-u update existing packages JAR file (JAR file to add files to the package)
[vfm0M] the option to choose, you can not run, they are jar command options parameters
-v generate a detailed report and print to standard output
-f specify JAR file name, usually this parameter is necessary
-m specify the need for a list of documents contained in MANIFEST
-0 Store only, not compressed, so that packets generated JAR files will be not more than the size of the parameters, but faster
-M does not produce a list of all items (MANIFEST〕 document, this parameter will ignore the-m parameter
[jar-file] the need to generate, view, update or remove the JAR file package, which is a subsidiary of the parameters-f parameter
[manifest-file] that is, a list of MANIFEST files, it is the-m parameter of the subsidiary parameters
[-C directory] said to continue the implementation of the specified directory jar command's operation. It is equivalent to using the cd command to change the directory and then the implementation of non--C of the jar command parameters, it can only create and update the JAR file when the package is available.
Specify a file name ... file / directory listing, the file / directory is added to the JAR file to package the file / directory. If you specify a directory, then the jar command automatically when the package to the directory of all files and subdirectories into the package.
The following give some examples to illustrate the usage of jar command:
1) jar cf test.jar test
The order of the implementation process did not show the results of the implementation is generated in the current directory test.jar document. If the current directory already exists test.jar, then the file will be overwritten.
2) jar cvf test.jar test
The order with the previous results were the same, but the role of the parameters v, showing that the packing process, as follows:
Marked list (manifest)
Increase: test / (read = 0) (write = 0) (stored 0%)
Increase: test / Test.class (read = 7) (write = 6) (14% compression)
3) jar cvfM test.jar test
The order and 2) the results of similar, but test.jar generated document does not contain META-INF/MANIFEST, packing process information is also slightly different:
Increase: test / (read = 0) (write = 0) (stored 0%)
Increase: test / Test.class (read = 7) (write = 6) (14% compression)
4) jar cvfm test.jar manifest.mf test
Results and 2) similar, showing the same information, but to generate the JAR package META-INF/MANIFEST content, are included in the contents of manifest.mf
5) jar tf test.jar
Test.jar already exists in the case, you can view the contents test.jar, such as for 2) and 3) generated by this command should test.jar respectively The results are as follows;
-------------------------------------------------- ------------------------------
3 JAR file jar command packet and explain
For 2)
META-INF /
META-INF/MANIFEST.MF
test /
test / Test.class
For 3)
test /
test / Test.class
6) jar tvf test.jar
In addition to display 5) shows that the content, the document also includes a detailed package of information, such as:
0 Wed Jun 19 15:39:06 GMT 2002 META-INF /
86 Wed Jun 19 15:39:06 GMT 2002 META-INF/MANIFEST.MF
0 Wed Jun 19 15:33:04 GMT 2002 test /
7 Wed Jun 19 15:33:04 GMT 2002 test / Test.class
7) jar xf test.jar
Test.jar to remove the current directory, do not show any information, for 2) generated test.jar, remove the directory structure after the following:
==
| - META-INF
| `- MANIFEST
`- Test
`- Test. Class
jar xvf test.jar
Results and 7) the same process for extracting detailed information display, such as:
Created: META-INF /
Expand: META-INF/MANIFEST.MF
Create: test /
Expand: test / Test.class
9) jar uf test.jar manifest.mf
Test.jar added in the document manifest.mf, the use of jar tf to see test.jar can be found in test.jar one more than the original manifest. This way, if you are using-m parameter and specify a document manifest.mf, then as a list of manifest.mf to use the MANIFEST file, its contents will be added to the MANIFEST in; However, if as a general document added to the JAR file package, it is no different from ordinary paper.
10) jar uvf test.jar manifest.mf
And 9) the results of the same, at the same time detailed information display, such as:
Increase: manifest.mf (read = 17) (write = 19) (-11% reduced)
4. On a number of JAR package skills
1) unzip to extract the JAR file
In introducing the document when JAR have said, JAR files are actually ZIP files, so you can use some common ZIP file decompression tool to extract the JAR file, such as the Windows of WinZip, WinRAR, etc., and under Linux such as the unzip. Use, such as WinZip and WinRAR to extract because they extract the relatively intuitive and convenient. Using unzip, unzip it is because it can use the-d when the parameter specifies the target directory.
A JAR file in the decompression of the jar can not be used when the-C parameter to specify the goal of extracting as-C parameter only in the creation or when the update package available. Then need to unzip the file to a specified directory when it needs to first copy a JAR file to the target directory and then extract, is too much trouble. If you are using unzip, do not have such a trouble, and only need to specify a-d parameter. Such as:
unzip test.jar-d dest /
2) the use of tools such as WinZip or WinRAR to create JAR file
JAR files mentioned above is included in the ZIP file META-INF/MANIFEST, therefore, only need to use WinZip, WinRAR and other tools needed to create compressed ZIP package, further compression of the ZIP package to add a MANIFEST file that contains the META-INF directory can be. Jar command using the-m parameter specifies the list of documents, just as necessary to modify this to MANIFEST.
3) the use jar command to create ZIP files
Some of Linux to provide the unzip command, but no zip command, so it is necessary to carry out on-extracting ZIP file that can not create a ZIP file. To create a ZIP file, use with-M parameter to the jar command, for-M parameters that, when the production of JAR package MANIFEST did not add the list, then the only goal in the designated place JAR files. Jar extension changed . zip extension, create a ZIP file of the letter, such as the one on the first 3) examples of minor changes:
jar cvfM test.zip test
original web please visit:
http://tieba.baidu.com/f?kz=111140030








Responses to “JAR file jar command packet and explain”