• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with Manifest classpath

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

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 in advance,
John.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your Class-Path entries would work if they reference the jar files outside your JAR. So this would not work. Check One-Jar for what you need.

Now I'm using Maven, because I hoped it would do some magic ....


Which kind of magic ?

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

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.

John.
 
John Sutt
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

John.
 
reply
    Bookmark Topic Watch Topic
  • New Topic