Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Jar file in jar file

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy,

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.

Regards,

- Tim
 
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:



Geoffrey
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic