Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migration to JDK 11 has error occure "java.lang.NoClassDefFoundError: javax/activation/DataSource" (tomcat 9.0.12) [duplicate]

I'm migrating java project use JDK8 to use JDK 11 then has error occurred relate of javax activation. Following migration guide from Oracle, I see java.activation that module was removed from JDK 11.

After that, I give a suggest to added third parties **activation-1.0.2.jar* but still, an error has occurred? Please give a suggestion about problem ? and could you tell me about experience of Migration source code use Java 8 to Java 11 (server with tomcat 9.0.12. compiler by Eclipse 2018-09(4.9.0)

This is detail error :

Caused by: java.lang.NoClassDefFoundError: javax/activation/DataSource
    at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
    at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3167)
    at java.base/java.lang.Class.getDeclaredMethods(Class.java:2310)
    at org.apache.catalina.util.Introspection.getDeclaredMethods(Introspection.java:133)
    at org.apache.catalina.startup.WebAnnotationSet.loadMethodsAnnotation(WebAnnotationSet.java:285)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:138)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:69)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:328)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:768)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5007)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
like image 349
SuperBeam Avatar asked Oct 22 '18 03:10

SuperBeam


1 Answers

You seem to have included an incorrect artifact(external jar).

You should include javax.activation:javax.activation-api:1.2.0 as an external dependency to your project to explicitly access the class javax.activation.DataSource. Sample maven dependency for the same would be:

<dependency>
  <groupId>javax.activation</groupId>
  <artifactId>javax.activation-api</artifactId>
  <version>1.2.0</version>
</dependency>

Also, note if using modularised code (includes module-info.java), you must state a dependence on the library using declaration -

requires java.activation;
like image 179
Naman Avatar answered Nov 15 '22 15:11

Naman