Let say, my physical class file is located in /common and I put a soft link to this in the WEB-INF/classes of a webapp. (using the ln command - RH Linux). In this case, this class would be loaded by which class loader? The classloader of the webapp or the common class loader?
I'm not entirely sure about soft linking and classloading on Linux, but I can tell you it is probably a bad strategy. You are playing with fire and, even if this works for the moment, will probably get burned in the future. Think about this; if the class is successfully loaded by the parent via the link, will that newly loaded class then have access to it's own dependencies which, presumably, exist in WEB-INF/class or WEB-INF/lib? Even if it did work, you common library would now have loaded a separate class than the classes in WEB-INF/classes and WEB-INF/lib. Not physically separate, but separate because a class' identity is define not only by itself, but by the classloader that loaded it. Again, even if it did work momentarily, you would probably end up with odd ClassCastExceptions.
You have to think about classloading behavior from the beginning if you plan on using separate classloaders. Separate components which shouldn't depend on each other at compile time. If you do that, then you will know about classloading dependencies before runtime because nothing will compile until you get it straight. In certain cases, you might find that if you want to share certain libraries, that entails sharing others. In other cases, you can factor out the dependency, thereby creating a better separation of concerns between your classes.
Moral of the story. Be wary of using quick fix solutions for classloader problems.... or use JBoss and figure that everything is in a single classloader. Good luck with that one as well. It always sounds good until you get to the details. Just be wary.
Jake
Ankit
----- Original Message ----- From: "Cox, Charlie" <[EMAIL PROTECTED]> To: "'Tomcat Users List'" <[EMAIL PROTECTED]> Sent: Friday, June 25, 2004 7:27 PM Subject: RE: class loader interdependencies
Classes in /common and /shared can not see classes in /WEB-INF. A class loaded by the nth classloader will not see any classes loaded by (n-1) classloader. However, it will see classes loaded by n+1 loader. This is the classloader hierarchy. Any classloader only has one parent to which it can delegate any classes that it can not resolve. Since multiple classloaders(one for each webapp) can have the same parent, the common classloader would not know which "WEB-INF" to reference when searching for a class.
Therefore all your classes need to be in /common if any within /common reference them. As an alternate, you can copy all classes to each /WEB-INF.
Charlie
> -----Original Message----- > From: Larry Levin [mailto:[EMAIL PROTECTED] > Sent: Friday, June 25, 2004 9:30 AM > To: [EMAIL PROTECTED] > Subject: class loader interdependencies > > Hi all; > > I am trying to share some jars across multiple web-apps, each of which > runs in its own environment (i.e, JVM). To do this I make use of the > CATALINA_BASE environment variable. My problem is in regards to class > loading. > > I have a number of jar files that are common to each webapp but I also > have a couple that are unique to each app. According to the > documentation for Tomcat 4.1: "from the perspective of a web > application, class or resource loading looks in the following > repositories, in this order:" > > 1) /WEB-INF/classes of your web application > 2) /WEB-INF/lib/*.jar of your web application > 3) Bootstrap classes of your JVM > 4) System class loader classes > 5) $CATALINA_HOME/common/classes > 6) $CATALINA_HOME/common/endorsed/*.jar > 7) $CATALINA_HOME/common/lib/*.jar > 8) $CATALINA_BASE/shared/classes > 9) $CATALINA_BASE/shared/lib/*.jar > > I have therefore tried two different approaches, both of which fail for > the same reason. > > 1st approach: I modified the standard startup script to add the shared > jars to the CLASSPATH, thereby treating them as System class loader > classes (i.e., category #4 in the above sequence). > > 2nd approach: I placed the shared jars in $CATALINA_HOME/common/lib > (i.e., category #7 in the above sequence). > > In both cases everything works fine UNTIL one of these shared classes > needs to access a class located in one of the /WEB-INF/lib/*.jar of a > web application (i.e., category #2). At that point my code throws a > ClassNotFoundException. > > My impression is that something in the class loader procedures prevents > "loading backwards" by which I mean: > > IF Class X was loaded by the nth loader in the sequence (e.g., #4, > the system loader), > AND Class X references a previously unloaded class, > THEN Tomcat will ignore any loader lower in the sequence the > Class X's loader > (e.g., loaders 1-3 (the /WEB-INF and bootstrap loaders > in this example)) > when attempting to resolve the reference. > > Is this a correct assumption and does anyone have a suggestion for > working around this "feature"? > > Thanks > > Larry > > > > > > -- > > Lawrence J Levin > Critical Architectures, LLC > Skillman NJ 08558 > email: [EMAIL PROTECTED] > voice: (609) 333-9750 > cell: (908) 227-8485 > fax: (609) 333-9751 > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
