Eclipse Build executable jar package [go]

Source: Internet
Author: User
Tags export class

I believe that in the development of Java will meet the requirements of the Java project to be packaged into a workable jar, today I in this blog in detail on the generation of the two methods of running the jar, the pro-test is completely feasible.

1. The project does not contain a third-party jar package

This is relatively simple, select the project that needs to generate the jar, right-click-->export, the following window appears

With the Java---> JAR file selected, the following window appears,

Here to:

Select Export generated class files and resources;
Select Compress the contents of the JAR file;
Select Overwrite existing files without warning;

Then "Next", the following window appears

Select Export class files with compile errors;
Select Export class files with compile warnings;

Click "Next" and the following window appears

Select "Main class" and then "Finish" OK.

How to run the jar package:

CMD, go into the jar where the package is located, run the command Java-jar *.jar, and you can. Or directly configure the file association.

2. When the project contains a third-party jar package

If the project contains a third-party jar package, the installation of the above method of production of the jar package, at run time will be reported java.lang.NoClassDefFoundError error, after Google, Baidu many sites, found the need to install Eclipse plug-ins, Plugin address is: http://sourceforge.net/projects/fjep/Download the file is "Net.sf.fjep.fatjar_0.0.31.zip", After decompression you will see the Net.sf.fjep.fatjar_0.0.31.jar file in the Plugins folder (called The Fat Jar).

How Fat jar plug-ins are installed:

Copy the Fat jar file to the plugins in your Eclipse directory. Restart your Eclipse platform and look at window---preferences, with the Fat jar preferences in the pop-up window indicating that you have successfully installed, without which the installation was unsuccessful. Take a few more steps: Go to the configuration---org.eclipse.update in your eclipse directory, delete the Platform.xml file, and then restart Eclipse. View Window---Preferences , you'll find the Fat jar, which looks like this:

Next, you can build a runnable jar package that contains a third-party jar package.

Select Project, right-click-> Export---> Other---> Fat jar exportor, as shown,

Next---> select the project to generate the jar package-> Next---> Appear as shown in the interface

Here you need to set Main-class, whose value is the main class of the project run, and tick the One-jar, click Next to appear as follows:

That is, the third-party class library referenced by the project, click "Finish", which generates a runnable jar package containing a third-party jar package. Above on the effect of Eclipse 3.6.2 (blue title bar) and Eclipse 4.2.1 (red title bar), if it is under Eclipse 3.6 version (specific version is not determined because I have not tried), after the selected project right click, there will be a build Fat Jar, As shown,

The next steps are similar.

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.