Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Tomcat 5.5: JavaMail Resource ClassCastException
Tomcat 5.5: JavaMail Resource ClassCastException [message #133883] Sun, 21 August 2005 14:24 Go to next message
Eclipse UserFriend
Originally posted by: eclipse.2rue.de

Hello everybody,

I'm using Eclipse 3.1, WTP0.7 and Tomcat 5.5 running on Ubuntu. In my
web application, I'm using JavaMail. I have defined and configured the
mail session in WEB-INF/web.xml and META-INF/context.xml, as described here:

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resourc es-howto.html

During init() of one of my servlets, I execute the following code to get
the properly configured javax.mail.Session object:

Object o = envContext.lookup("mail/Session");
Session mailSession=(Session) o;

When I deploy the webapp and start tomcat outside of eclipse, this works
just fine. When I start the webapp in Eclipse, the second line of code
throws a ClassCastException. Funnily, Object o has javax.mail.Session as
its class. So I checked the classloaders of o's class and class
javax.mail.Session, and what goes - they are different:

o.getClass().getClassLoader().toString():
org.apache.catalina.loader.StandardClassLoader@dbe178

javax.mail.Session.class.getClassLoader().toString():
WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@872380

The JavaMail jars are in $CATALINA_HOME/common/lib. If I put them in
WEB-INF/lib, I get a NoClassDefFoundError with a stacktrace pointing to
Tomcat's resource initialization.

Is there any way around this? Should this be filed as a bug?



greetings from Berlin,

Rüdiger
Re: Tomcat 5.5: JavaMail Resource ClassCastException [message #134118 is a reply to message #133883] Mon, 22 August 2005 14:16 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
I believe the StandardClassLoader difference is normal. The
StandardClassLoader@872380 instance is likely "shared/lib", whose parent
class loader is the StandardClassLoader@dbe178 instance. The problem
would appear to be that your servlet using the javax.mail.Session found
in your "WEB-INF/lib" and the resource configuration is using the
javax.mail.Session from "common/lib". According to the documentation
you cite, the mail.jar (and activation.jar) should not be in your
WEB-INF/lib.

Check your ".deployables" directory structure to ensure it's not in that
"WEB-INF/lib", then take whatever steps are necessary to prevent its return.

Cheers,
Larry


Rüdiger Schulz wrote:
> Hello everybody,
>
> I'm using Eclipse 3.1, WTP0.7 and Tomcat 5.5 running on Ubuntu. In my
> web application, I'm using JavaMail. I have defined and configured the
> mail session in WEB-INF/web.xml and META-INF/context.xml, as described
> here:
>
> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resourc es-howto.html
>
> During init() of one of my servlets, I execute the following code to get
> the properly configured javax.mail.Session object:
>
> Object o = envContext.lookup("mail/Session");
> Session mailSession=(Session) o;
>
> When I deploy the webapp and start tomcat outside of eclipse, this works
> just fine. When I start the webapp in Eclipse, the second line of code
> throws a ClassCastException. Funnily, Object o has javax.mail.Session as
> its class. So I checked the classloaders of o's class and class
> javax.mail.Session, and what goes - they are different:
>
> o.getClass().getClassLoader().toString():
> org.apache.catalina.loader.StandardClassLoader@dbe178
>
> javax.mail.Session.class.getClassLoader().toString():
> WebappClassLoader
> delegate: false
> repositories:
> /WEB-INF/classes/
> ----------> Parent Classloader:
> org.apache.catalina.loader.StandardClassLoader@872380
>
> The JavaMail jars are in $CATALINA_HOME/common/lib. If I put them in
> WEB-INF/lib, I get a NoClassDefFoundError with a stacktrace pointing to
> Tomcat's resource initialization.
>
> Is there any way around this? Should this be filed as a bug?
>
>
>
> greetings from Berlin,
>
> Rüdiger
Re: Tomcat 5.5: JavaMail Resource ClassCastException [message #134294 is a reply to message #134118] Mon, 22 August 2005 21:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.2rue.de

Hello Larry,

your assumption was wrong, but your implication was just the right thing :-)

Actually, I had the mail.jar and jaf.jar removed from my
WebContent/WEB-INF/lib directory, and refreshed my project, but never
looked into .deployables - and there were still copies there! So I
removed them, and gone were the exceptions. Thanks a lot!

What was wrong is that the ClassLoader difference would be normal. Now,
both classes have the same ClassLoader, and only then they can be
considered equal. Because I learned while searching the web for
conclusions, that a Class is defined by its fully qualified name *and*
its ClassLoader (e.g. here:
http://forum.java.sun.com/thread.jspa?threadID=493181&me ssageID=2321223)
So, I hadn't heard about that one before. Doesn't happen too often I think.

Another thing with JavaMail (and actually any other library) is, that
you can't put the .jars into $CATALINA_HOME/shared/lib directory, as
that would not be recognized while using the internal Tomcat of WTP -
you have to put them into common/lib. But that is already discussed in
another thread on this group, and also filed as a bug.

So thanks again for your help :-)


- Rüdiger



Larry Isaacs schrieb:
> I believe the StandardClassLoader difference is normal. The
> StandardClassLoader@872380 instance is likely "shared/lib", whose parent
> class loader is the StandardClassLoader@dbe178 instance. The problem
> would appear to be that your servlet using the javax.mail.Session found
> in your "WEB-INF/lib" and the resource configuration is using the
> javax.mail.Session from "common/lib". According to the documentation
> you cite, the mail.jar (and activation.jar) should not be in your
> WEB-INF/lib.
>
> Check your ".deployables" directory structure to ensure it's not in that
> "WEB-INF/lib", then take whatever steps are necessary to prevent its
> return.
>
> Cheers,
> Larry
>
>
> Rüdiger Schulz wrote:
>
>> Hello everybody,
>>
>> I'm using Eclipse 3.1, WTP0.7 and Tomcat 5.5 running on Ubuntu. In my
>> web application, I'm using JavaMail. I have defined and configured the
>> mail session in WEB-INF/web.xml and META-INF/context.xml, as described
>> here:
>>
>> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resourc es-howto.html
>>
>> During init() of one of my servlets, I execute the following code to
>> get the properly configured javax.mail.Session object:
>>
>> Object o = envContext.lookup("mail/Session");
>> Session mailSession=(Session) o;
>> When I deploy the webapp and start tomcat outside of eclipse, this
>> works just fine. When I start the webapp in Eclipse, the second line
>> of code throws a ClassCastException. Funnily, Object o has
>> javax.mail.Session as its class. So I checked the classloaders of o's
>> class and class javax.mail.Session, and what goes - they are different:
>>
>> o.getClass().getClassLoader().toString():
>> org.apache.catalina.loader.StandardClassLoader@dbe178
>>
>> javax.mail.Session.class.getClassLoader().toString():
>> WebappClassLoader
>> delegate: false
>> repositories:
>> /WEB-INF/classes/
>> ----------> Parent Classloader:
>> org.apache.catalina.loader.StandardClassLoader@872380
>>
>> The JavaMail jars are in $CATALINA_HOME/common/lib. If I put them in
>> WEB-INF/lib, I get a NoClassDefFoundError with a stacktrace pointing
>> to Tomcat's resource initialization.
>>
>> Is there any way around this? Should this be filed as a bug?
>>
>>
>>
>> greetings from Berlin,
>>
>> Rüdiger
Re: Tomcat 5.5: JavaMail Resource ClassCastException [message #134319 is a reply to message #134294] Mon, 22 August 2005 23:33 Go to previous message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
Hi Rüdiger,

I'm glad you got it working. Just to clarify to finish the thread, the
parent classloader of the WebappClassLoader (WEB-INF/classes &
WEB-INF/lib) will be a StandardClassLoader ("shared/lib"), whose parent
classloader will also be a StandardClassLoader ("common/lib"). So it's
normal for the classloader instance for "common/lib" not to be the same
classloader instance that is the parent of the "WEB-INF" classloader,
though they are both StandardClassLoaders. I didn't mean to imply it
would be normal to try and use the same class from different classloaders.

Cheers,
Larry

Rüdiger Schulz wrote:
> Hello Larry,
>
> your assumption was wrong, but your implication was just the right thing
> :-)
>
> Actually, I had the mail.jar and jaf.jar removed from my
> WebContent/WEB-INF/lib directory, and refreshed my project, but never
> looked into .deployables - and there were still copies there! So I
> removed them, and gone were the exceptions. Thanks a lot!
>
> What was wrong is that the ClassLoader difference would be normal. Now,
> both classes have the same ClassLoader, and only then they can be
> considered equal. Because I learned while searching the web for
> conclusions, that a Class is defined by its fully qualified name *and*
> its ClassLoader (e.g. here:
> http://forum.java.sun.com/thread.jspa?threadID=493181&me ssageID=2321223)
> So, I hadn't heard about that one before. Doesn't happen too often I think.
>
> Another thing with JavaMail (and actually any other library) is, that
> you can't put the .jars into $CATALINA_HOME/shared/lib directory, as
> that would not be recognized while using the internal Tomcat of WTP -
> you have to put them into common/lib. But that is already discussed in
> another thread on this group, and also filed as a bug.
>
> So thanks again for your help :-)
>
>
> - Rüdiger
>
>
>
> Larry Isaacs schrieb:
>
>> I believe the StandardClassLoader difference is normal. The
>> StandardClassLoader@872380 instance is likely "shared/lib", whose
>> parent class loader is the StandardClassLoader@dbe178 instance. The
>> problem would appear to be that your servlet using the
>> javax.mail.Session found in your "WEB-INF/lib" and the resource
>> configuration is using the javax.mail.Session from "common/lib".
>> According to the documentation you cite, the mail.jar (and
>> activation.jar) should not be in your WEB-INF/lib.
>>
>> Check your ".deployables" directory structure to ensure it's not in
>> that "WEB-INF/lib", then take whatever steps are necessary to prevent
>> its return.
>>
>> Cheers,
>> Larry
>>
>>
>> Rüdiger Schulz wrote:
>>
>>> Hello everybody,
>>>
>>> I'm using Eclipse 3.1, WTP0.7 and Tomcat 5.5 running on Ubuntu. In my
>>> web application, I'm using JavaMail. I have defined and configured
>>> the mail session in WEB-INF/web.xml and META-INF/context.xml, as
>>> described here:
>>>
>>> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resourc es-howto.html
>>>
>>>
>>> During init() of one of my servlets, I execute the following code to
>>> get the properly configured javax.mail.Session object:
>>>
>>> Object o = envContext.lookup("mail/Session");
>>> Session mailSession=(Session) o; When I deploy the webapp and start
>>> tomcat outside of eclipse, this works just fine. When I start the
>>> webapp in Eclipse, the second line of code throws a
>>> ClassCastException. Funnily, Object o has javax.mail.Session as its
>>> class. So I checked the classloaders of o's class and class
>>> javax.mail.Session, and what goes - they are different:
>>>
>>> o.getClass().getClassLoader().toString():
>>> org.apache.catalina.loader.StandardClassLoader@dbe178
>>>
>>> javax.mail.Session.class.getClassLoader().toString():
>>> WebappClassLoader
>>> delegate: false
>>> repositories:
>>> /WEB-INF/classes/
>>> ----------> Parent Classloader:
>>> org.apache.catalina.loader.StandardClassLoader@872380
>>>
>>> The JavaMail jars are in $CATALINA_HOME/common/lib. If I put them in
>>> WEB-INF/lib, I get a NoClassDefFoundError with a stacktrace pointing
>>> to Tomcat's resource initialization.
>>>
>>> Is there any way around this? Should this be filed as a bug?
>>>
>>>
>>>
>>> greetings from Berlin,
>>>
>>> Rüdiger
Previous Topic:How to upgrade wtp-0.7RC3 to wtp-0.7
Next Topic:Installation Woes w/WTP .7
Goto Forum:
  


Current Time: Sat Jul 27 12:19:44 GMT 2024

Powered by FUDForum. Page generated in 0.03106 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top