Monday, June 1, 2009

Create .jar file

I developed "Ration Data Entry System" for Sri Lanka Army, during my training at DMS Ltd.
The system developed using java, Oracle and HSQLDB. This project contain so many third party libraries such as iText.jar, Hsqldb.jar, etc...
The Netbeans IDE supports to build the jar files. It creates the jarfiles and MANIFEST but the problem is the classpath for the third part libraries are set to out side thr jar file. I needed just one jar file to deliver the produsct. So follow the following procedure.

1. Created an executable JAR file with the application’s CLASS files in it. Name this “main.jar”
jar cfm main.jar manifest.txt *.class
2. Created three directories: MAIN, LIB, and BOOT
3. Placed “main.jar” file in the MAIN directory
4. Placed the jar files that the main application depends on in the LIB directory
5. Created a new JAR file out of the MAIN and LIB directories. Name this one “application.jar”.
jar cf application.jar main lib
6. Extract the contents of the “one-jar-boot.jar” file into the BOOT directory(one-jar-boot.jar is a third party jar file, can download)
7. Navigated to the BOOT directory, and update the “application.jar” file with the following:
jar -uvfm ../application.jar *.*

My “application.jar” file is now be executable.
It is running when moving the "application.jar" to another directory or another computer too.


No comments:

Post a Comment