This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes ClassCastException in JavaMail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ClassCastException in JavaMail" Watch "ClassCastException in JavaMail" New topic
Author

ClassCastException in JavaMail

Dawn Thomas
Greenhorn

Joined: Nov 05, 2007
Posts: 5
I'm working on some code. This code works in 2 environments but no in the third. This is the code:

in TagHandler.java
InitialContext initial = new InitialContext();
System.out.println("in sendMail - looked up JavaMail session " + Attr.MAIL_SESSION_LOOKUP);
Session session = (Session)initial.lookup(Attr.MAIL_SESSION_LOOKUP);
System.out.println("in sendMail - creating email and sending it");

The code is getting to the first println but not the second. The MAIL_SESSION_LOOKUP is set to what it should be in the println and on the server, the Mail session name is correct - I checked that. I'm getting a ClassCastException.

The really funny thing is - I didn't change the code. I had to rebuild my computer in January and I have deployed the same code since then and that is when my troubles began. I'm running j2sdk 1.4.2_13 and I believe the code was developed in either j2sdk 1.4.2_04 or 1.4.2_06. I tried copying the mail.jar files off another computer where the code was created but this hasn't helped.

Any suggestions??
Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
Just a blind guess, but maybe check which Session you have imported.

If that's not the case, consider the possiblity of a classloader problem:

http://smallwig.blogspot.com/2007/10/understanding-cls.html

Goodluck!

EDIT**

I just parsed the first line, that it works in 2 environments but not the third. This is probably a classloader issue.
[ November 05, 2007: Message edited by: Adam Schaible ]
Dawn Thomas
Greenhorn

Joined: Nov 05, 2007
Posts: 5
This is the import I have:

import javax.mail.Session;
Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
Originally posted by Dawn Thomas:
This is the import I have:

import javax.mail.Session;


I would guess you're having a class loader issue. This could probably be moved into the advanced forum - I can tell you how to fix it, but there are probably more elegant ways.. try this.



This is probably not perfect, I've never had to deal with a situation like this, but I'd probably start with something like this - maybe someone that has experience with it can come in and help.
Dawn Thomas
Greenhorn

Joined: Nov 05, 2007
Posts: 5
Hi,

Thanks for your help. It turns out that I have something configured wrong in my new IDE. I recently switched from Sun One to Rational Application Developer and there is some manual configuration I need to do that I was not aware of.

The code works fine when deployed from Sun One.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassCastException in JavaMail
 
Similar Threads
JavaMail Exception "HELO requires domain address"
ClassCastException - JavaMail & JNDI in Application Client
javax.mail package
ClassCastException
configuring JavaMail with Sendmail