Eclipse packaging tool fatjar

Source: Internet
Author: User
Tags configuration settings

A few days ago, I saw a good eclipse packaging tool that can package all referenced jar files and implement a jar package. In this way, your program and other referenced jar files can be run as independent programs, which is very convenient. Introduction:
The fat jar Eclipse plug-in is a deployment-tool which deploys an eclipse Java-project into one executable jar.

It adds the entry "build fat-jar" to the export-wizard.
In addition to the eclipse standard jar-exporter referenced classes and jars are encoded to the "Fat-jar ", so the resulting jar contains all needed classes and can be executed directly with "Java-jar", no classpath has to be set, no additional jars have to be deployed.

Jars, external-jars, user-libraries, system-libraries, classes-folders and project-exports are considered by the plugin.
The main-class can be selected and manifest-files are merged.
The one-jar option integrates a specialised class-loader written by Simon tuffs (http://one-jar.sourceforge.net/) which handles jar-files inside a jar.
Individual files and folders can be excluded or added to the jar.
Different settings can be stored and re-executed as "quick build" via the context-menu.

Here is an introduction to the usage method, which is very simple, as follows:

Fat jar Eclipse plug-in tutorial

 

Step 1:Create a new Java project "demolib"

Create a new Java project named "demolib ".
Add the class "demolib. demolib. Java" containing the following code:

package demolib;

public class DemoLib {
public static void sayHello() {
System.out.println("Hello");
}
}

The project shoshould look something like this:

 

Step 2: Create a jar file using fat jar plug-in

In the "package-Explorer" (not the "resource-View") Right click on the project "demolib ".
Select "+ build fat jar ".

A configuration dialog appears. Just press "finish ".

The file "demolib_fat.jar" has been created in the project root directory.

 

Step 3: Create a New Java-project "demorun"

Create a new Java project named "demorun ".
In the project properties Add the library "demolib/demolib_fat.jar" to the Java build path ":

 

Step 4: Create main class

Add the class "demorun. demorunmain. Java" containing the following code:

package demorun;

import demolib.DemoLib;

public class DemoRunMain {
public static void main(String[] args) {
DemoLib.sayHello();
}
}

The project shoshould look something like this:

 

Step 5: Start the build fat jar Dialog

Start the export wizard from the file-menu ("file"-> "Export ").
Select "+ Fat jar exporter" and click "next> ".

Select the project "demorun" and click "next> ".

A configuration-dialog appears showing the current settings.

 

Step 6: Select the main class

The main class-the one containing the static methode main-must be defined in the jar.
Click on the "Browse..." button on the right side behind the main-class edit field.

Select "demorunmain" and click the "OK" button.
The fullyqualifiedname "demorun. demorunmain" is now set for "Main-class ".

 

Step 7: Finish

Save the current settings by clicking on the "finish" button.

The file "demorun_fat.jar" has been created in the project root directory.
In addition the file ". fatjar" storing the configuration settings has been created in the project root directory

The created JAR file contains all classes from all referenced jar files (demolib_fat.jar) and the project classes.
This file can be executed anywhere, no classpath has to be set, because all necessary Libraries
Are extracted inside the "Fat jar ":

> java -jar demorun_fat.jar
Hello
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.