【发布时间】:2014-04-07 08:32:18
【问题描述】:
我在eclipse和tomcat服务器中使用maven。
我必须制作一个小程序,如果需要,每隔一小时使用 java 邮件发送一封电子邮件。
我在 webapp 中修改了我的 web.xml。
我像这样在 POM.xml 中添加了邮件。
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>activation</artifactId>
<groupId>javax.activation</groupId>
</exclusion>
</exclusions>
</dependency>
因为我使用的是 jdk 1.6,所以不需要激活。
我还修改了 context.xml
然后将 mail.jar 复制到 tomcat/lib 文件夹中。
但我遇到了奇怪的错误。
java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session
at fr.project.batch.jobs.SendEmail.execute(SendEmail.java:53)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
2014-04-07 10:01:47,539 ERROR duler_Worker-1 Job (DEFAULT.SendMail threw an exception. [ErrorLogger]
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session]
at org.quartz.core.JobRunShell.run(JobRunShell.java:227)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session
at fr.project.batch.jobs.SendEmail.execute(SendEmail.java:53)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
... 1 more
我在 tomcat 6.0 JavaMail 资源中阅读了很多遍,并阅读了许多 stackoverflow 的答案。
【问题讨论】:
标签: java eclipse maven tomcat jakarta-mail