0

I keep getting the NoClassDefFoundError error. I am trying to send an email using the JavaMail API, but the error occurs when I'm creating an instance of Message using the SMTPMessage class.

I know I need the activation library, but it still doesn't work.

By the way, I'm using JDK 10.

The error happens on the first line of this code.

@Override
public void sendEmail(Mail mail) throws MessagingException
{
    Message message = new SMTPMessage(this.session);
    message.setSubject(mail.getHeader());
    message.setFrom(mail.getFrom());
    message.setSentDate(mail.getDateClone());

    if (mail.getSignature() != null)
        message.setText(mail.getText() + "\n\n" + mail.getSignature());

    else
        message.setText(mail.getText());

    Transport.send(message);
}

Stacktrace

Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource
at martin.mail.EmailHandler.sendEmail(EmailHandler.java:79)
at martin.Main.main(Main.java:22)
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 2 more
jreznot
  • 2,694
  • 2
  • 35
  • 53

1 Answers1

-1

Solution

Just add the activation library to your own class path. You can put it in your own package.