Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Email delivery

Sending mail from Java fails with NoClassDefFoundError: javax/activation/DataSource

Errorjava.lang.NoClassDefFoundError: javax/activation/DataSource

Short answer

JavaMail needs the JavaBeans Activation Framework. It was part of the JDK until Java 10 and was removed in JDK 11, so it must now come from your project. Add the activation jar to the runtime classpath, and check that it is packaged: a provided scope or an IDE run setting can leave it out.

  • Applies to JDK 17, JDK 21, Maven 3.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check which Java runs the program and whether the activation jar is on its classpath. On JDK 11 or newer there is no built-in copy.

    java -version
    mvn dependency:tree | grep -i activation
  2. 2Match what you see, then jump to its fix

    1. 1java -version shows 11 or higher and the dependency tree has no activation artifact.The JDK no longer includes the activation moduleFix
    2. 2It compiles and works in one run configuration, but the packaged jar, a container or an IDE run fails.The jar is a compile-time dependency only and is missing at runtimeFix

What does the error look like?

  • java.lang.NoClassDefFoundError: javax/activation/DataSource
  • java.lang.ClassNotFoundException: javax.activation.DataSource

Cause 1 of 2

The JDK no longer includes the activation module

1Check

Oracle's migration guide says the Java EE and CORBA modules were removed in JDK 11, java.activation among them, and that code on the class path that uses them fails with a missing-class error. The Jakarta Mail FAQ says the activation jar must be on the classpath.

mvn dependency:tree | grep -i "activation\|mail"

2Fix

Put the activation jar on the runtime classpath, next to your mail library, using the version your mail library documents. For Angus Mail the project home lists jakarta.activation-api for compiling and angus-activation for runtime; the versions below are placeholders for the ones that page names.

<dependency>
  <groupId>jakarta.activation</groupId>
  <artifactId>jakarta.activation-api</artifactId>
  <version>${jakarta.activation.version}</version>
</dependency>
<dependency>
  <groupId>org.eclipse.angus</groupId>
  <artifactId>angus-activation</artifactId>
  <version>${angus.activation.version}</version>
  <scope>runtime</scope>
</dependency>

3Verify

The tree now lists the activation artifacts, and the send runs.

mvn dependency:tree | grep -i activation

Confirmed by eclipse-ee4j.github.io

Did this fix it?

Cause 2 of 2

The jar is a compile-time dependency only and is missing at runtime

1Check

A provided scope is on the compile and test classpath but not the runtime classpath, because Maven expects the JDK or a container to supply it. Nothing supplies it on JDK 11 or newer.

grep -n -B3 -A3 "activation" pom.xml

2Fix

Use compile or runtime scope for the activation dependencies, rebuild the package, and run from that package.

<dependency>
  <groupId>org.eclipse.angus</groupId>
  <artifactId>angus-activation</artifactId>
  <version>${angus.activation.version}</version>
  <scope>runtime</scope>
</dependency>

3Verify

Rebuild and run the packaged application.

mvn clean package
java -jar target/app.jar

Confirmed by maven.apache.org

Did this fix it?

How do I stop it coming back?

  • Do not assume the JDK carries Java EE libraries; declare each one your code uses.
  • Run the packaged artifact, not only the IDE, as part of every release check.
  • Pin the mail and activation versions in one place in the pom.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Email

Django send_mail fails or hangs with an SSL error

smtplib.SMTPException raised from send_mail()

Django has two secure modes that must not be mixed: EMAIL_USE_TLS for explicit TLS (STARTTLS, usually port 587) and EMAIL_USE_SSL for implicit TLS (usually port 465).

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.