1. 程式人生 > >java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger for JUnit test case for Java mail

java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger for JUnit test case for Java mail

The JavaMail API is available as an optional package for use with Java SE platform and is also included in the Java EE platform.

99% that you run your tests in SE environment which means what you have to bother about adding it manually to your classpath when running tests.

翻譯過來就是:JavaMail API在Java SE 平臺是可選的,在Java EE 平臺是自動包含的,你很有可能是Java SE的環境,因此,需要手動導包。

<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.3</version>
</dependency>

這兩個包一個都不能少,特別是第二個,往往都是這個包沒有匯入。