File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassCastException in JavaMail

 
Dawn Thomas
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the import I have:

import javax.mail.Session;
 
Adam Schaible
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic