Skip to content

java.lang.ClassCastException after the JNDI lookup of javax.mail.session

October 24, 2009

This issue is due to a mismatch of jar files. The jboss lib folder $JBOSS_HOME$/server/default/lib/ contains the mail.jar file. (Java Mail library) And as usualĀ  you may have included the Java Mail Library jar in your deployed project. (.war or .ear). Both the libraries has the javax.mail.Session class. So the class loader will load the both as two different classes. This originates the issue.

javax.mail.Session session = (javax.mail.Session) context.lookup(“)

Here you going to load the java mail session from a jndi lookup. So the contex.lookup(“..”) returns a javax.mail.Session_JBOSS object. Now you try to cast it. But unfortunately the javax.mail.Session class used in your code is loaded as a different class (javax.mail.Session_USER). So java throws an ClassCastException.

Remove the java mail jar file from the lib folder of your application. It will work fine.

I have experienced the above issue for several other libraries too (log4j).

Hope this will help.

Rgs,

Lasith.

Advertisement

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.