Requirements: Deploy the local Java program to a Linux server and execute it, first make the local Java program into a jar package, then copy it to the server and run Java-jar Xx.jar
Problem: The program is running normally locally, the server side is running the error can not find the class in the third party package
Reason: There was an error in the local jar pack and failed to introduce the third party package correctly
Workaround: Package locally through the Fat Jar plug-in, as follows
Java application packaged MAINFEST.MF format under EclipseFirst, ensure that the program executes correctly under Eclipse, and then the following methods:
(write at the top of the eclipse package or use the plug-in Fat jar)
Download Address: http://sourceforge.net/project/showfiles.php?group_id=115990&package_id=125924
Instructions for use:
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 should 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 should 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 is 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 '.
Step7: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 to all referenced jar files (Demolib_fat.jar) and the project classes. br> This file can is executed anywhere, no classpath has to is set, because all necessary libraries
are extracted ins IDE the "Fat Jar":
> Java-jar demorun_fat.jar
Hello