Eclipse export jar (java package export jar)

Source: Internet
Author: User

Sometimes you need to export the j2se project so that it can operate elsewhere, so you don't have to stick to the feeling of development before it can run.
The procedure is as follows:
Method 1: (export directly when the project does not reference an external jar package)

Select project ----> right-click, Export... ---> Java ---> JAR file ---> next --> select the path and name of jar file --> next ---> Select main class ---> finish.

Method 2:

When other external jar packages are referenced in the project, eclipse does not support exporting the external jar package at the same time, so it is more troublesome. The specific steps are as follows:
Generate manifest file: select the project ---> right-click, Export ---> Java ---> JAR file ---> select the path and name of jar file ---> next;
At this time, the window for Selecting main class in method 1 is displayed, but the main class is not selected here. Select the Generate the manifest file at the top, and check the Save the manifest in the workspace, in Manifest file:, enter the file name, such as/testProject/main. (testProject is the project name and main is the name of manifest file.) Click finish and return to the project, open the generated main, and enter the following information here:
Manifest-Version: 1.0
Main-Class: com. pacong. convert. auto. propertes. ConvertAutoProperties
Class-Path: jxl. jar
Among them, Manifest-Version: 1.0 is the Version number of the newly generated manifest;
Main-Class: com. pacong. convert. auto. propertes. ConvertAutoProperties is the class where the main Class is located;
Class-Path: jxl. jar is the name of the external jar package, which indicates the Path and name of the external jar package to be used.
After completing the preceding steps, you can export the jar package with the external jar package. The steps are as follows:
Select project ---> right-click, Export ---> Java ---> JAR file ---> select the path and name of jar file ---> next, at this time, I came to the window for Selecting main class, but I didn't select main class here. I chose Use existing manifest from workspace and selected the generated main in Manifest file:, for example: /testProject/main, click finish, and the result is complete. Assume that the generated jar package is named test. jar, then the jxl. jar and test. jar is located in the same directory.

Note the following points:
To run the generated jar in the command line, run the following command:
Java-jar test. jar
If the jar contains some System. out. prinln statements, run the following command to view the printed content:
Java-jar test. jar> log.txt
The output information will be printed to log.txt. Of course, log.txt is automatically generated and located in the same directory as test. jar.

You can also create a new start. bat file, after creation; right-click --- edit, enter: java-jar test. jar> log.txt; double-click start. bat to run test. jar.

Note: If you export files to an Elastic Block Storage (edisk), you need to import the packages to this 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.