java.lang.NoClassDefFoundError:com / sun / mail / util / LineInputStream用于通过Java发送邮件

时间:2018-05-16 06:43:05

标签: java javamail

这是我的例外LineInputStream

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
        at javax.mail.Session.loadProvidersFromStream(Session.java:928)
        at javax.mail.Session.access$000(Session.java:174)
        at javax.mail.Session$1.load(Session.java:870)
        at javax.mail.Session.loadAllResources(Session.java:1130)
        at javax.mail.Session.loadProviders(Session.java:886)
        at javax.mail.Session.<init>(Session.java:210)
        at javax.mail.Session.getDefaultInstance(Session.java:299)
        at com.pack.utils.SendMail.sendMail(SendMail.java:67)
        at com.pack.utils.SendMail.sendMail(SendMail.java:34
)
    at com.pack.utils.SendMail.main(SendMail.java:133)

我的依赖关系罐是 java 1.6 mailapi-1.4.4

我在这行收到错误

sessions[0] = Session.getDefaultInstance(props, null);  

2 个答案:

答案 0 :(得分:2)

将此添加到您的pom,或将JAR添加到您的类路径

<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>1.6.0</version>
</dependency>

答案 1 :(得分:0)

此解决方案可以帮助我

我在 java.policy 文件中添加了文件权限,我将Java6更改为Java7

permission java.io.FilePermission  "<<ALL FILES>>", "read"; };

C:\Program Files\Java\jre1.7.0\lib\security此路径中提供的java.policy文件