We've upgraded our application to Spring6/Tomcat10 (that implies migration from Java EE to Jakarta) and could not find jakarta compatible alternative for apache commons-email library?!
We seem to have decent amount of custom code that uses commons-email. Have anyone else run into this issue before? What our options are?
After performing the initial research I can think of the following options (and to be honest I don't like neither one of them :-():
- Refactor our code to use jakarta.mail where commons-email library is used? (Seem to be a significant effort).
- Fork source code of the commons-email library and migrate it to jakarta ourselves? (Have anyone taken this route? If it's that straight-forward wondering why maintainer of the commons-email project have not done that already?)
- We tried to keep both javax-mail and jakarta-mail libraries in the classpath, and keep using commons-email in the places where it's used and it works most of the time, but sporadically throws:
java.lang.ClassCastException: class com.sun.mail.handlers.multipart_mixed cannot be cast to class jakarta.activation.DataContentHandler (com.sun.mail.handlers.multipart_mixed and jakarta.activation.DataContentHandler are in unnamed module of loader 'app')
Is there anything else we can do? Any help with be greatly appreciated!
You can clone the commons-email repo and compile it locally. It's at version 1.6-SNAPSHOT, and seems to depend on jakarta already. I'd update the dependencies while you're at it. To illustrate, I copied MimeMessageParser from version 1.5 and replaced javax with jakarta in the imports, and that works with a one-to-one correspondence for the javax/jakarta classes I looked at. When (for instance) mvnrepository catches up with version 1.6 you can go back to using that.