After changing from OracleJDK 8 to OpenJDK 11, JavaMail now raises the following exception and cannot send emails at all.
java.lang.NoClassDefFoundError: javax/activation/DataSource
(Abbreviation)
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource
This article will show you how to use JavaMail with OpenJDK 11 and above.
JavaMail uses the java.activation
package internally, but in OpenJDK 11 and later, JEP 320: Remove the Java EE and CORBA Modules Package has been removed.
Due to the removal of the java.activation
package, the class referenced by JavaMail cannot be found and the exception shown in the overview has occurred.
You can use JavaMail by using the JavaBeans Activation Framework (https://mvnrepository.com/artifact/com.sun.activation/javax.activation) as the java.activation
package.
Maven
<!-- https://mvnrepository.com/artifact/com.sun.activation/javax.activation -->
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
Gradle
// https://mvnrepository.com/artifact/com.sun.activation/javax.activation
compile group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'
Recommended Posts