ClassCastException occurs in my web app, because classloaders load 
the same class twice, when two web apps share WebLogic wlfullclient.jar. 
Any idea how to avoid that? Details below.

Project set-up:
- Tomcat 6.0.13 + Weblogic 10.0
- wlfullclient.jar is placed in <TOMCAT_HOME>\lib.
- two web apps are deployed on Tomcat (WebApp1 & WebApp2). 
The wep apps don't share any libraries except wlfullclient.jar.
- both web apps are subscribed to weblogic JMS topic.

Error scenario:
1. a message is generated in the weblogic JMS topic
2. both web apps retrieve the message
3. logic that handles the message in WepApp2 operates on a certain 
class that belongs to WebApp2 (let's call the class "XXX" for convenience). 
Namely, the logic contains casting: 
Object xxxObject = someJndiLookup();
XXX someVariable = (XXX) xxxObject;
4. Casting results in ClassCastException. Debugging shows that 
xxxObject is an object of the XXX class and its loaded by WebLogic 
GenericClassLoader. And the object is cast to the XXX class 
loaded by WebApp2ClassLoader.

Reason:
At the server startup, WebLogic GenericClassLoader (that is 
provided within wlfullclient.jar) is loaded and it sets 
WepApp1ClassLoader as its parent.
XXX class is a part of WepApp2 and obviously is loaded by
WepApp2ClassLoader.
When Weblogic JMS message comes up, GenericClassLoader has to deal 
with an object of the XXX class. According to the classloaders 
delegation model GenericClassLoader first asks its parent whether 
the parent knows XXX. But - surprise - the parent of GenericClassLoader 
is WepApp1ClassLoader. Obviously WepApp1ClassLoader does not know 
this class, since it belongs to WebApp2. That's why GenericClassLoader 
decides to load the class itself.
As a result there are multiple copies of the same class.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to