Hello everyone,
I have a class which has a static method that can be called to set a
static variable in the class. This class is a socket factory to be
used by JavaMail,
to replace the standard socket creator so that it binds to the right
address.
Anyway, I am able to call the static method on the class, that works
fine.
Then I create the JavaMail session, passing in some properties,
including one undocumented property, called
"mail.smtp.socketFactory.class." I pass in the full classname (with
package reference) for my class, just exactly as I used when I called
the static method:
com.myname.plugins.mail.RemoteDeliverySocketFactory
(Yes, this class was borrowed from the Apache James project. ;-)
When it comes time for the class to be loaded by JavaMail to create
the socket and connection, I get the ClassNotFoundException. It makes
absolutely no sense to me, as I was able to call the static method on
the class already, so I know the JVM can find the class! The exact
error is:
javax.mail.MessagingException: Could not connect to SMTP host:
iatn.net, port: 25;
nested exception is:
java.io.IOException: Couldn't connect using
"com.iatn.plugins.mail.RemoteDeliverySocketFactory" socket factory to
host, port: iatn.net, -1; Exception: java.lang.ClassNotFoundException:
com.iatn.plugins.mail.RemoteDeliverySocketFactory
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:911)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:158)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134)
at javax.mail.Service.connect(Service.java:86)
at com.sun.mail.smtp.SMTPTransport.connect(SMTPTransport.java:95)
at com.myname.plugins.mail.SMTPConn.sendEmail(SMTPConn.java:1606)
at com.myname.plugins.mail.SMTPConn.run(SMTPConn.java:466)
at java.lang.Thread.run(Thread.java:534)
Any ideas?
Thanks!
Thomas
Jacques Desmazieres - 24 May 2004 07:33 GMT
How did you set up your classpath, and mainly how do you reference the
classes of your JavaMail library ?
This seems to be a common classloader problem. For instance if your JavaMail
library is in the jre lib directory, then it cannot access the classes that
would be defined in the classpath environment variable (or -classpath
parameter).
In that case, moves the JavaMail library from the jre lib directory to your
app directory, and add it to the classpath.
Hope this helps
Jacques Desmazieres
> Hello everyone,
>
[quoted text clipped - 31 lines]
> at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:911)
> at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:158)
> at javax.mail.Service.connect(Service.java:233)
> at javax.mail.Service.connect(Service.java:134)
[quoted text clipped - 9 lines]
>
> Thomas
Thomas - 24 May 2004 14:00 GMT
Hello Jacques,
> How did you set up your classpath, and mainly how do you reference the
> classes of your JavaMail library ?
All my libs are in c:\java\jre\lib\ext. This includes the JavaMail
jar, and my own classes that work with javamail. I checked, and the
JavaMail library is not located anywhere else on the system.
This is what is so bizarre... it makes no sense to me. The class
loader
can see the RemoteDeliverySocketFactory class when I am calling it
from
my code, but when the JavaMail classes try to load it they get CNFE,
even
though we're all in the same library directory, same classpath, same
VM.
I'm trying to figure out a way that I can get JavaMail to print out
where
it is looking for classes.
Thanks for trying to help.
Thomas