Eclipse:java.lang.NoClassDefFoundError:javax / activation / DataHandler [英] Eclipse: java.lang.NoClassDefFoundError: javax/activation/DataHandler

查看:267
本文介绍了Eclipse:java.lang.NoClassDefFoundError:javax / activation / DataHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用Java发送电子邮件。
这是代码:

I'm trying to send an email in java. Here's the code:

String mailSmtpHost = "smtp.example.com";
String mailTo = "email@example.com";
        String mailFrom = "email@example.com";
        String mailSubject = "Email subject";
        String mailText = "Some text";
        Properties properties = new Properties();
        properties.put("mail.smtp.host", mailSmtpHost);
        Session emailSession = Session.getDefaultInstance(properties);
try {
            Message emailMessage = new MimeMessage(emailSession);
            emailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(mailTo));
            emailMessage.setFrom(new InternetAddress(mailFrom));
            emailMessage.setSubject(mailSubject);
            emailMessage.setText(mailText);
            emailSession.setDebug(true);
            Transport.send(emailMessage);
        }catch(Exception e) {
            System.out.println("Errore email: "+e.toString());
        }

编译项目时,在线:

Message emailMessage = new MimeMessage(emailSession);

...出现以下错误:

...the following error comes out:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataHandler

注意:我正在使用 java -version:9.0.4

推荐答案

JDK 9默认禁用对许多javax。* API的访问,现已弃用javax激活。

JDK 9 disables access to many of the javax.* APIs by default, javax activation is now deprecated.

但是您可以解决它在运行时添加模块

However you can resolve it with adding the module at run time

"--add-modules java.activation".

这篇关于Eclipse:java.lang.NoClassDefFoundError:javax / activation / DataHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆