This article describes how to use the eclipse + fjep plug-in to package a Java project into a single executable jar, so that a single jar can be released even if an additional third-party jar is used.
Fjep: http://fjep.sourceforge.net/
Fjep tutorial (http://fjep.sourceforge.net/fjeptutorial.html) explains how to use fjep to package, fjep's job is to expand the third-party jar, directly put the third-party classes in the form of a folder (Package) into the customer jar
For example, the customer project is fjepdemo (only one Java file: fjepdemo/demo. java), uses a lib (jar) as fjeplib. jar (including: fjeplib/lib. class), the structure of the file packaged with fjep is as follows:
Fjepdemo. Jar
/Fjepdemo/demo. Class
/Fjeplib/lib. Class
Fjeplib. jar is no longer in the form of jar in the newly released jar.
If the third-party jar rule does not allow publishing modification, it cannot be expanded in this way. At this time, one-jar can be used for processing, "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."
One-Jar has been integrated into fjep. The check box one-jar can be checked in the package. fjeplib is hit to fjepdemo. jar/lib/fjeplib. jar.
In addition, if the project uses additional resource files, such as I/O operations, to read and write a TXT file, it cannot be read and written in a common file path. Package fjepdemo;
Import fjeplib. Lib;
Import java. Io .*;
Public class demo ...{
/***//**
* @ Param ARGs
*/
Public static void main (string [] ARGs) throws ioexception ...{
// Todo auto-generated method stub
Lib. Print ();
Inputstream is = demo. Class. getresourceasstream ("/1.txt"); // note the path of the resource file
System. Out. println (is. Available ());
}
}
The structure of the packaged file is as follows:
Fjepdemo. Jar
META-INF
...
/Main
...
/Lib
Fjeplib. Jar
/COM
... // The content of One-jar
1. txt
Run the jar> JAVA-jar fjepdemo. jar on the console.
Refer:
Http://fjep.sourceforge.net/
Http://one-jar.sourceforge.net/
Http://www-128.ibm.com/developerworks/cn/java/j-onejar/