转自:https://blog.csdn.net/u013361445/article/details/49663329
关于使用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>
参考:http://stackoverflow.com/questions/16807758/java-lang-noclassdeffounderror-com-sun-mail-util-maillogger-for-junit-test-case
pom.xml引入依赖
<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包
参考:http://javahonk.com/java-lang-classnotfoundexception-javax-mail-messagingexception/
最终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 >