Jar File

Creating a Jar file from your existing Application is very easy. Using Ant it is a simple target:

  


 * jarfile determines the output file (the jar file you want to create).


 * manifest determines the manifest to use.


 * and with the fileset tag you select the files and folders you want to include in the jarfile.

This is pretty simple since you have a small project without any external libraries like other jar files.

If you want to use other jar files in your project it becomes a little more comlicated. The normal way is to create your jarfile and make a reference to the extra libs in the manifest file. With Class-Path: lib/extralib.jar you can tell your application that the necessary files are contained in a lib directory next to your jar file. This way works fine, since you don't bother the folder which you have to deliver with your jar file.

If you want to deliver only one file (your jar file) you need a new ClassLoader developed by Simon Tuffs.

His One-Jar.jar allows to create a jar file that contains all the stuff it needs.

What you have to do is:
 * unjar the One-Jar.jar into an folder (temp)
 * create a folder temp/main and copy your own jar into it
 * create a folder temp/lib and copy all necessary external jars into it
 * create a jar file containing all files and folders in temp

You can use an Ant script as follows:            