Package the Java project as jar in eclipse

Source: Internet
Author: User
If you need to reference additional jar packages as resource files in your Java project, you need to customize the configuration file manifest. MF as follows:

Manifest-version: 1.0
Class-path: lib/Crimson. Jar lib/jbcl. Jar lib/JUnit. Jar lib/log4j-1.2.13.jar lib/mysql-connector-java-3.1.13-bin.jar
Main-class: SRC. yourmainclassname

The class-paht specifies the location of the external jar package. Note that we assume that our project is packaged as a project. jar, according to the above definition, it should be in the project. create a lib folder under the same-layer directory of jar, and put the relevant jar package in it. Otherwise, the exception in thread "Main" Java. Lang. noclassdeffounderror error may occur.

Finally, let's introduce how to use eclipse to create a jar package:

1. Open the project in eclipse, right-click the project, and select "Export ";

2. Select Java/JAR file and next;

3. In select the resources to export, you can select the project folder you want to include. Some unnecessary folders do not need to be put in, so as not to increase the space;

There are several options:

* Export generated class files and Resources indicates that only generated. class files and other resource files are exported.
* Export all output folders for checked projects: export all folders of the selected project
* Export Java source file and Resouces indicates that the exported jar package will contain yourSource code*. Java, if you do not want to leak the sourceCode, So do not select this option.
* Export refactorings for checked projects include some reconstructed information files.

In select the export destination, select the path of the exported jar, next

4. On the next page, you can choose whether to export the *. class files containing warning warnings or error errors. Ignore him, next

5. Configure the project on the next page.

* Generate the manifest file is used by the system to automatically generate the manifest. MF file. If your project does not reference other class-path files, you can select this item.
* Use existing mainfest from workspace. This is a custom. MF file. The format is as shown above.
* Seal content. Packet
* Main class. Here you can select yourProgramThe jar package in the future is the execution result of your entry class.

Finish.

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.