Two ways to explain Jar pack (DOS Pack jar Eclipse package jar file) _java

Source: Internet
Author: User


1. Packaging jar files under DOS





code as follows:

D:\jdk1.5.0_07\bin> Jar/help





Usage:jar  {ctxu}[vfm0mi]  [jar-file]  [manifest-file]  [-c  directory]  filename   ...
Options:
-c  Create a new archive
-t  List of archived content
-x  expand a named (or all) file in the archive
-u  Update an existing archive
-v  Generate verbose output to standard output
-f  specifies the archive file name
-m  contains the marked information from the marked file
-0  storage only; not in zip compression
-m  Does not produce a manifest for all items (the Manifest) file
-i  generates index information for the specified jar file
-c  changes to the specified directory,
runs the jar just generated on the command line, as follows:
Java-jar Test.jar
If you have some SYSTEM.OUT.PRINLN statements in the jar and want to see what is printed after you run it, you can use the command:
Java-jar test.jar >log.txt
The output information is printed to Log.txt, and of course log.txt is automatically generated and located in and Test.jar a directory.
You can also create a new Start.bat file, after the creation of the right key---edit, input: Java-jar Test.jar >log.txt; after the direct double-click Start.bat can run Test.jar.
Note that if you are exporting files in a file such as: E disk, then you need to import the package also to put in this directory.
If a file name is a directory, it will be processed recursively. The
manifest (manifest) file name and archive file name are all required to be specified in the same order as the ' m '   and   ' F ' flags.



Example 1: Archive two class files into an archive file called ' Classes.jar ':
Jar CVF Classes.jar Foo.class bar.class
Example 2: Using an existing manifest (manifest) file ' Mymanifest ' will foo/the directory of all
Files are archived to an archive file called ' Classes.jar ':
Jar CVFM Classes.jar mymanifest-c foo/.



2. Packaging jar files with eclipse



Eclipse generates a jar package by packaging the Java class file by exporting it (right-clicking the project, then selecting Export).



Method One: (Export directly when the project project does not refer to an external jar package)


 code as follows:

Selected Projects----> Right button, Export ...--->java--->jar file--->next--> Select the path and name of JAR file-->next-->next---> Select Main Class--->finish





Method Two:
When the project references other external jars, it is more cumbersome because Eclipse does not support the ability to export the external jar packs at the same time, as shown in the following steps:



Generate manifest File: Selected Project---> Right, Export--->java--->jar file---> select the path and name of JAR file--->next--->next--- >next;



At this point in Method 1 to select the Main class window, but here first select the main class, select the top of the generate the manifest file, hook up save the manifest in the workspace, Manif EST file: Enter the name of the file, such as/testproject/main, (where TestProject is the project name, Main is the name of manifest file) Click Finish, return to the project, open the just generated main, Here you enter the following information:



manifest-version:1.0
Main-class:com.pacong.convert.auto.propertes.convertautoproperties
Class-path:jxl.jar



Where manifest-version:1.0 is the Manifest version number that is just automatically generated;



Main-class:com.pacong.convert.auto.propertes.convertautoproperties is the class where main class is located;
Class-path:jxl.jar is the name of the external jar package, which is the path and name of the external jar package you want to use to tell the exported jar package.
All done above you can export the jar package with the external jar package, as follows:


code as follows:

Selected Project---> Right, Export--->java--->jar file---> select the path and name of JAR file--->next--->next--->next, Then came the window to select Main class, but here also does not select Main class, choose Use existing manifest from workspace, in manifest file: Select the main that just generated, such as:/ Testproject/main, click Finish, you're done here; Assuming the name of the generated jar package is Test.jar, the Jxl.jar to be introduced in Class-path is located in the same directory as the Test.jar.





Here's one more thing to note:



If you want to run the jar you just built on the command line, the command is as follows:
Java-jar Test.jar
If you have some SYSTEM.OUT.PRINLN statements in the jar and want to see what is printed after you run it, you can use the command:
Java-jar Test.jar >log.txt
The output information is printed to Log.txt, and of course log.txt is automatically generated and located in and Test.jar a directory.


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.