关于使用JavaMail过程中遇到两个错误
1.java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
2.
java.lang.NoClassDefFoundError: javax/mail/MessagingException
pom.xml 原先配置
-
<dependency>
-
<groupId >javax.mail </groupId >
-
<artifactId >javax.mail- api</ artifactId>
-
<version >
1.5.1 </version >
-
<scope >test </scope >
-
</dependency>
解决方案:
1.
java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
MailLogger
--是JavaMail的一部分,包含在Java EE环境里面,但是不包含在Java SE环境里面,出现这个错误很大的原因是在SE环境里面测试邮件的发送;javax.mail-api只适合编译,但是如果你实在要运行代码,必须完全实现JavaMail
可以用<groupId>com.sun.mail</groupId><artifactId>javax.mail</artifactId>
pom.xml修改为
-
<span style=
"white-space:pre"> </span><dependency >
-
<groupId >com.sun.mail </groupId >
-
<artifactId >javax.mail </artifactId >
-
<version >
1.5.4 </version >
-
</dependency >
2.
java.lang.NoClassDefFoundError: javax/mail/MessagingException
是因为需要 mail.jar 这个jar包
最终pom.xml修改为
-
<dependency >
-
<groupId >javax.mail </groupId >
-
<artifactId >mail </artifactId >
-
<version >
1.4.5 </version >
-
</dependency >
-
<dependency >
-
<groupId >com.sun.mail </groupId >
-
<artifactId >javax.mail </artifactId >
-
<version >
1.5.4 </version >
-
</dependency >