问题
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.<init>(SendEmails.java:47)
...
回答1:
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.
回答2:
It is easy to forget to add jars in Tomcat's lib into Tomcats classpath. Project -> Run As -> Run Configurations -> YourServer -> Classpath tab. That helped in my case. Simply copying files into tomcat's lib folder does not suffice.
来源:https://stackoverflow.com/questions/21346643/javamail-1-5-1-tomcat-7-and-java-lang-classnotfoundexception-javax-mail-authe