What's Happening

Building jars

Jul 4th, 2008 by blog | 0

When developing a program you don’t want to write everything from scratch. Hence, including other libraries becomes standard. The easiest way to make use of the external libraries is to include a jar file. However, when you want to distribute your program as a jar file yourself, those external libraries come back to bite you: It is not possible to export dependent jar files along with your classes into one jar file.

Now, you could extract the classes from the jar file of the external library to put them into your jar file, but in most cases those libraries have dependencies of their own, which come as — guess what — jar files. So it becomes futile to attempt to include all the classes manually. Doing this in a an automated fashion seems more applicable. However, even when using ANT files to build your project, you still need to generate a jar file from all this with correct MANIFEST.MF file. (See tutorial.)

If you are using eclipse then all the hard work can be done for you by one small plug-in called fat-jar. One click (literally) and your classes and all necessary jar files of external libraries are packed nicely into a jar file, the proper MANIFEST is written and the whole thing can be accessed as :

java -jar myApplication.jar

Leave a Reply