What to do if JavaMail cannot be used with OpenJDK 11 or later

Overview

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.

Cause of exception

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.

approach

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

What to do if JavaMail cannot be used with OpenJDK 11 or later
What to do if the adb command cannot be executed
What to do when CentOS cannot be started with VirtualBox on Catalina
What to do if SPA URL loading cannot be detected by WebView shouldOverrideUrlLoading
What to do if rails server can't be stopped
What to do if the build fails with the error "Module compiled with Swift x.x.x cannot be imported by the Swift x.x.x compiler"
What to do if you cannot execute with the command "Java package name / class name"
[Java] [Spring] What to do if you cannot Autowire with Type Mismatch after annotating Spring Security
What to do if validation doesn't work with the update action
What to do if you get angry with OpenSSL with pyenv install
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
[Rails] What to do if you can't get parameters with form_with
What to do about the "cannot be read or is not a valid ZIP file" error
What to do if you install Ubuntu
[Composer] [Laravel] What to do if you cannot install due to insufficient memory
What to do if you get Could not locate Gemfile or .bundle / directory
[Rails 6] method :: delete cannot be used with link_to
What to do if the server tomcat dies
What to do if you push incorrect information
What to do if mvn archetype: generate fails
[Ubuntu] What to do when MongoDB cannot be started due to a SocketException error
[React.useRef] What to do when the latest state cannot be referenced in the event listener
What to do if the JSONHint annotation does not work with lombok and JSONIC
What to do if Android Studio says "your CPU doesn't support vt-x or svm"
What to do if the debug gem installation fails
What to do if the Rails server can't start
What to do if ClassNotFoundException occurs when starting Tomcat
What to do if TextToSpeech doesn't work on Android 11
What to do if you accidentally create a model
What to do if an ActionController :: UnknownFormat error occurs
What to do if password authentication fails in Docker/Postgres
What to do when Git Repository cannot be displayed in Team Explorer for Eclipse in Azure
What to do if you change the Listen Address from the settings screen with Mattermost docker
In SpringBoot 2.3.0 or later, the placeholder used for the value of @PropertySource fails to be resolved.
What to do if you installed Ruby with rbenv but the version does not change
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
[Rails] What to do if you can't get an error message with the errors method
What to do if you get a java.io.IOException in GlassFish
What to do when you launch an application with rails
What to do if audio is not available on discordrb
What to do if FacesMessage is set but not displayed
# What to do if you accidentally do rails db: migrate: drop
What to do when Cannot apply expression operators to method binding
What to do if mysql2 gets a bundle install error
What to do if you can't use the rails command
Notes on what to do if Ubuntu 20.04 installation on Virtual box 6.1 (Windows10) fails with "Error 5 Input / output error"
What to do if Intel RST (Rapid Storage Technology) interferes with dual booting Ubuntu20.04LTS and Windows10
What to do if an SSH key authentication error occurs during automatic deployment to EC2 with Capistrano
What to do if the app is not created with the latest Rails version installed when rails new
Because getSupportLoaderManager cannot be used
[Ubuntu 20.04] What to do if the external monitor is not recognized
What to do if you get a gcc error in Docker
[Rails] What to do if data is not registered in DB
What to do if the Rails page doesn't appear in Rails tutorial 1.3.2
What to do if Cloud9 is full in the Rails tutorial
What to do if the Eclipse Maven dependency Jar is wrong
[Rails] What to do when rails s does not respond or does not stop
What to do if you get a DISPLAY error in gym.render ()
java.security.InvalidKeyException: What to do when Illegal key size or default parameters
[Logback] What to do if unnecessary files do not disappear during rotation
What to do if you forget the root password in CentOS7