I trying to use Javamail 1.5.1 with Tomcat 7 and Eclipse Kepler.
When I try to send an email, Tomcat blows up with the error below...
From the docs, I understand that everything I need is now within the javax.mail.jar. And I have that in the webapp's WEB-INF/lib folder.
I think it's complaining that it can't find javax.mail.Authenticator. But I have confirmed that the class is within the jar.
This should be easy. Could someone please point out what I am missing?
I have also added the jar to eclipse preferences as a Library.
Also... where to I get the downloaded javadoc so I can add that to eclipse too? i.e. so I can hover the mouse over a word and get the docs?
Thanks
java.lang.NoClassDefFoundError: javax/mail/Authenticator
org.apache.naming.factory.MailSessionFactory.getObjectInstance(MailSessionFactory.java:106)
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
org.apache.naming.NamingContext.lookup(NamingContext.java:843)
org.apache.naming.NamingContext.lookup(NamingContext.java:154)
org.apache.naming.NamingContext.lookup(NamingContext.java:831)
org.apache.naming.NamingContext.lookup(NamingContext.java:168)
util.SendEmails.(SendEmails.java:47)
...
解决方案
I had exactly the same issue, and I fixed this by adding the Java Mail jar to the tomcat lib directory.
I'm thinking the cause of the error is that during the JNDI lookup the classes from the webapp itself are not loaded, so in order for the JNDI to work you need to provide the jar directly to tomcat, instead of in your webapp.