This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a simple java class with a main method that I intend to call in the following manner: java -jar helloWorld.jar
In the helloWorld class, I intend to do a little logging, so I include the log4j-1.2.8.jar in my project. It works great in the IDE (WSAD 5.1) but no so much when I creat the jar file and try to execute it from the command line.
I know that the problem is related to the log4j jar file. I rolled it into the helloWorld.jar and included it in the manifest file, but I still get the NoClassDefFound error. If I put the log4j jar file in the same directory as my jar, the command line works fine.
So my question really is: How do I write my manifest file to tell the app that the jar it's looking for is in another jar? Or is this even possible? I'd rather keep things bundled up into one file if at all possible.
The trick is getting the log4j classes where the jar classloader can find them. Probably the simplest thing to do is build a jar that contains the union of your classes and the log4j classes (and any other libs you use).
If you use Ant, you could do it using something like: