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.