Sending mail from Java fails with NoClassDefFoundError: javax/activation/DataSource
java.lang.NoClassDefFoundError: javax/activation/DataSourceShort 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.
Fix it fast
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 activation2Match what you see, then jump to its fix
- 1
java -version shows 11 or higher and the dependency tree has no activation artifact.The JDK no longer includes the activation moduleFix - 2
It 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
- 1
What does the error look like?
java.lang.NoClassDefFoundError: javax/activation/DataSourcejava.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 activationConfirmed by eclipse-ee4j.github.io
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.xml2Fix
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.jarConfirmed by maven.apache.org
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
Sending mail from Java fails with 530 5.7.0 Must issue a STARTTLS command first
530 5.7.0 Must issue a STARTTLS command first
The server will not take your login or message until the connection is encrypted, and your session never asked for TLS.
3 causes, each with a fixCodeIgniter email does not send and shows no error message
$email->printDebugger() prints an empty result
CodeIgniter signals a failed email only by send() returning false, with no exception.
4 causes, each with a fixDjango 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 fixDKIM shows 'bad version' or 'unknown key type' because the DNS key record is malformed
dkim=fail (unknown key type)
These results mean the receiver found your DKIM key record but could not use it.
4 causes, each with a fixSmtpException: Unable to read data from the transport connection (net_io_connectionclosed)
System.Net.Mail.SmtpException: Unable to read data from the transport connection: net_io_connectionclosed.
The server closed the connection while SmtpClient was waiting for a reply.
4 causes, each with a fixDovecot refuses to start: Can't load SSL certificate, no valid PEM certificate
doveconf: Error: ssl enabled, but ssl_cert not set
Dovecot reads the ssl_cert setting as the file's contents, not a path, so in 2.3 the value must start with a less-than sign.
3 causes, each with a fix