Several methods and plug-ins for eclipse to package Java app projects into jar

Source: Internet
Author: User

Recommended Practices:

It is very convenient to install a fatjar plug-in, and the generated jar package can be run, including referencing external jar packages and other files, which can be easily referenced in the jar package.

After installing the plug-in, right-click the plug-in and select "Export" in "other", select "Fat jar exporter", and then check some options.

 

Method 2: (I tried it many times and the compiled jar package can be run. However, after the jar package is changed to another directory, the system will prompt that the relevant jar package is missing. This is not recommended)

Jar packages for Java projects can be divided into two situations:

1. the Java project has not imported a third-party jar package

Packaging is simple at this time:

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 your source code *. java. If you do not want to disclose the source code, 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. (If the project does not introduce a third-party jar package, we can use the default system option. The main class must be set as the main method entry class of your project)
* 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 your program portal. The jar package in the future will be the execution result of your portal class.
Finish. ......

 

2. the Java project has imported third-party jar packages (for example, the project has imported the sqlserver2005.jar package)

Packaging is a little more complicated at this time:

The preceding four steps are the same as the above, except that you need to select the use existing mainfest from workspace option in step 1 and select a manifest created by yourself. mf file, because the system selects the generate the manifest file option by default, and this option does not include third-party jar packages used by the project into the jar package generated by the Java project.

Custom configuration file manifest. MF:

First, create a manifest. MF file under the root directory of the project.

Next, open the file in notepad and edit it:

For example:
Manifest-version: 1.0
Main-class: studentmanager_test
Class-path: sqlserver2005.jar
The manifest-version indicates the program version, and the main-class indicates the main method entry class of the program. The slass-path 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. jar has related jar packages (sqlserver2005.jar) in the same-layer directory. If multiple third-party jar packages are introduced, they can be separated by spaces. Otherwise, the exception in thread "Main" Java. Lang. noclassdeffounderror error may occur.

 

Note the following points:

1: the last line in the configuration file must be entered.

Manifest-version: 1.0
Main-class: SRC. guanyy. timetaskcreatedata
Class-path: sqlserver2005.jar

 

2: Main-class: The main function in can carry a package: for example:

Main-class :( a space) SRC. guanyy. timetaskcreatedata

Do not forget spaces in the middle

3: The statement in class-path is as follows:

Class-path :( one space) Lib \ mysql-connector-java-5.1.18-bin.jar (one space) Other jar packages

Class-path: Lib \ mysql-connector-java-5.1.18-bin.jar Lib \..

 

 

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.