Use eclipse to generate a runable jar package

Source: Internet
Author: User

I believe that when developing Java, you will surely encounter the need to package the Java project into a runable jar. Today, I will explain in detail how to generate a runable jar in this blog.

1. The project does not contain third-party jar packages

This case is relatively simple. Select the project to generate the jar and right-click --> export. The following window appears.

Select Java ---> JAR file --> next ---> main class. Select the default main class, and click Finish to generate a jar package that can be run.

How to run the jar package:

CMD: Enter the location where the jar package is located. Run the Java-jar *. Jar command.

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

If the project contains a third-party jar package, install the jar package produced by the above method. lang. noclassdeffounderror error, after Google, Baidu many websites, find the need to install Eclipse plug-in, plug-in address is: http://sourceforge.net/projects/fjep/ download file is net.sf.fjep.fatjar_0.0.31.zip, after decompression you will see the net in the plugins folder. SF. fjep. fatjar_0.0.31.jar (fat jar ).

Installation Method of the fat jar plug-in:

Copy the fat JAR file to the Plugins under your eclipse directory .. restart your eclipse platform and check window --- preferences. If the pop-up window contains fat jar preferences, it indicates that you have installed the program successfully. If this item is not installed successfully, perform the following steps: Go to configuration --- org under your eclipse directory. eclipse. update and delete platform. XML file, and then restart eclipse. view window --- preferences and you will find the fat jar. The effect is as follows:

Next, you can generate a runable jar package that contains a third-party jar package.

Select the project and right-click --> export ---> other ---> fat jar exportor. The effect is shown in,

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

Here, you need to set main-class, whose value is the main class running the project, and check one-jar, click Next ---> finish, in this way, a runable jar package containing a third-party jar package is generated. The above is based on the effect of eclipse 3.6.2. If it is a version earlier than eclipse 3.6 (the specific version is not clear, because I have not tried it), right-click the project selected, build fat jar, as shown in,

The following operations 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.