Affects: Spring 5.3.10


I upgraded the project to use java 17, the source code can compile but I got the java.lang.NoClassDefFoundError: javax/activation/DataSource when trying to send the email with JavaMailSenderImpl and MimeMessageHelper.

The code worked fine with java 8.

I have checked the class DataSource (in jakarta.mail version 1.6.7) and see that it was compiled with java 5. Seems like it can't work with java 17 for now, can anyone confirm this? and how can I overcome the problem?

Comment From: bclozel

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

See https://stackoverflow.com/search?q=java.lang.NoClassDefFoundError%3A+javax%2Factivation%2FDataSource+

You'll need to add the relevant jar since the classes were removed from the JDK. You should keep using the javax.* variants until you upgrade to Spring Framework 6.

Comment From: nxtruong72

Hi @bclozel ,

Here is the link that I have opened on the Stack Overflow: https://stackoverflow.com/questions/76627040/javamailsenderimpl-got-java-lang-noclassdeffounderror-javax-activation-datasour

I have added the dependency on jakarta.mail version 1.6.7 as on the link and recommendation from Spring Mail (https://docs.spring.io/spring-framework/docs/5.3.10/reference/html/integration.html#mail)

Comment From: bclozel

@nxtruong72 answered your question on SO. This is most likely an issue with your build.

Comment From: nxtruong72

@bclozel could you please try to send the email with your sample code with java 17? I can build it successfully but got the error at run time.

Note that the code worked fine with java 8, but not for java 17.