views:

1090

answers:

4

Tomcat Version :5.0.28 JDK: 1.5.0.14

The problem:

I am using both hibernate and struts We are not on the latest and greatest of the version for these libraries So- both need a different version of apache-commons library.

The solution I have in mind:

Use manifest file and specify a different version of apache-commons for each

My web app is deployed as webapps\myapp

And the lib is webapps\myapp\WEB-INF\lib

I modified the Manifest.mf in hibernate3.jar as follows

Manifest-Version: 1.0

Archiver-Version: Plexus Archiver Created-By: 1.5.0_15-b04 (Sun> Microsystems Inc.) Class-Path: hibernatelib/slf4j-api-1.5.2.jar

and put the slf4j-api-1.5.2.jar in webapps\myapp\WEB-INF\lib\hibernatelib

Now I would expect that slf4j-api-1.5.2.jar would be loaded automatically along with hibernate But its not working... Tomcat is unable to find the jar files specified in the .MF as above

The Question:

  1. Am I doing something wrong? or is it Tomcat ?
  2. Is there another solution to this problem ?

I have already tried\checked the following

  1. Checked for new-line characters at the end of the file
  2. If I put slf4j-api-1.5.2.jar in the main lib folder- the error goes away- so I know its not able to find this particular jar file
  3. Tried relative, absolute path in the manifest file
A: 

Have you checked any permissions are correct? Also might be an idea to ensure there's a newline after that last Class-Path line, that helped me out earlier today!


Update: if Tomcat doesn't support classpath declarations like this, the only thing that springs to mind involves messing around with ClassLoaders. Personally I wouldn't do that - there's a whole world of potential pain down that path and you'll probably have an easier time just upgrading. Sorry I can't think of a better answer!

Brabster
Yes- I have checked for new-line.What permission do I need to check ?
RN
Just checking out the spec @ http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html I think you should make sure there's a newline after each entry, it's in the grammar.
Brabster
Sorry, probably not permissions. I've seen a few references around that say you Tomcat will ignore classpath stuff declared in manifest files in WEB-IN/lib - nothing official though, sorry.
Brabster
Thanks, Saua and Brabster for the helpI will hang around and see if anyone else has a thought on this.This seems so fundamental- there must be a structured solution for thisI agree- I do not want to mess around with custom class-paths
RN
A: 

The only place where the Class-Path attribute in the manifest is used is when the jar containing the manifest is called as an executable jar using ("java -jar theFile.jar").

Some servlet containers seem to support it, but according to this mailing list post (Sorry, couldn't find anything more authorative so quickly) it's not specified in the spec either.

As far as I understand it, web applications generally load their classes using a single class loader. "Correctly" solving that dependency problem would require at least 2 different classloaders.

A hack-ish solution might be to use jarjar or a similar tool to package the different libraries together with their respective dependencies.

So you'd produce one jar containing Hibernate together with its apache-commons library and another jar containing struts together with its apache-commons library. Each copy of the apache-commons library would be moved to different packages (possibly hibernate.org.apache.* and struts.org.apache.*) to solve the problem with different classe versions.

Joachim Sauer
Alright- then how do you achieve what I am trying to do ?I have a shared library between two different librariesHow do I reconcile them ?
RN
KoolThis helpsI tried to up your answer but didn't have enough reps :)
RN
No problem, glad I could help.
Joachim Sauer
A: 

Have you tried the latest, greatest version of Tomcat to see if the problem still persists? Tomcat 6 is already several years old, let alone 5.5 or 5.0...

R. Bemrose
Not yet.I guess I can try that and see if the problem goes away.But that will not really help me. Upgrading Tomcat right now is not an option .
RN
A: 

I don't believe that you can do this. Tomcat isn't looking at JAR manifests to decide CLASSPATH issues. It's using its own hierarchy of class loaders to find what it needs, using what it says CLASSPATH is.

If you want different versions of a JAR for different parts of your app, you sound like a person who really needs OSGi. That's the problem is was invented to solve.

There are two competing JSRs out there, but I don't know of any implementations for the Sun module proposal.

The one app server that I know of that will allow you to do this is Spring's DM server. It's a fork of Tomcat that they're enhancing.

duffymo