I'm trying to create a test .jar file, which includes other jars, I 'm using log4j-1.2.14.jar as my first test,
but getting the manifest file right (or something else?...) is driving me a bit nuts.
Now I'm using Maven, because I hoped it would do some magic and teach me how to do it right, but I ran
into the same problem as when I tried to do what I want manually.
My jar has the following structure:
App.class is the trivial Maven Hello world example, and I added a simple log.debug call to it with log4j. Note that this application works perfectly fine without packaging it into a jar.
The MANIFEST.MF file inside the jar looks like this:
Now, if a run "java -jar myJarFile.jar" I get the following error:
Why can't it find the log4j jar file ??? When I removed the lib/ from Classs-path and copied the log4j jar file to its parent directory, it also did not work with the same error.
Thanks for pointing me to One-Jar. It looks nice, but I'd also like to know how to make this work without one-jar.
I understand now, that without special classloading code, I have to put the log4j outside of my own .jar file.
I've put log4j-1.2.14.jar and myJar.jar in the same directory. The MANIFEST file inside myJar.jar looks like this:
There is no log4j classes or jars inside myJar.jar.
Both of the following command lines produce the same error:
About Maven, I just meant that I hoped it would create a working example for me, such that I could copy it and learn from it.
Joined: Mar 07, 2008
Aha, I finally found out how to get it working.
I did not tell the whole story yet. In my Ant build file,
I'd put an "index=true" which also generated an index
file together with the manifest in the meta-inf directory.
And that was the culprit, ... for some reason.
When I removed the index, suddenly the log4j classes did get found.
I guess, in case of such an index file, the classloader does not look outside
of the .jar anymore, or something like that.
Glad I got it fixed, though, and thanks for your help.