• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassCastException in JavaMail

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the import I have:

import javax.mail.Session;
 
Adam Schaible
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic