UPDATE It seems this is at least partly outdated, have a look at manifestclasspath.
It is possible to define .jar dependencies in the MANIFEST.MF of the main .jar file, it is just a comma seperated string which looks like this:
Class-Path: lib/log4j.jar lib/commons.jar
In a project I work on, we keep all our dependencies in a lib directory, where we add and remove libraries from time to time, therefore it would be nice if the above text can be generated automatically. Fortunately, this is possible using just Ant. Unfortunately, this is rather cumbersome. (If you want something more powerful and simpler to use, have a look at Rake).
In a nutshell, this is how I did it:
- First, let’s define some properties:
- Now to the fun part, create a nice .jar file. This generates the MANIFEST.MF but first generates a property libs.project that contains all .jar files, sperated with space. If you later look at the generated MANIFEST.MF you will notice that the paths are wrapped every 72 character, even in the middle of the word. Although this looks like an error, it works correctly.
- Finally we need to create a distribution by copying all .jar files into dist/lib while using a flat directory structure:
I use Ant 1.6.2, and this works perfectly for me. Have fun!