9

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)
Naman
  • 27,789
  • 26
  • 218
  • 353
SuperBeam
  • 91
  • 1
  • 1
  • 2

1 Answers1

21

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;
Naman
  • 27,789
  • 26
  • 218
  • 353
  • 4
    `javax.activation:javax.activation-api:1.2.0` is not a module, so `requires java.activation` has no meaning. In Java 9 and 10, you can use `requires java.activation` or `--add-modules java.activation` *instead of* including the dependency. In Java 11+ the module doesn't exist in the JDK anymore, so `requires java.activation` won't work there. – Andreas Oct 22 '18 at 04:21
  • @nullpointer Thank you for your help, I don't use maven on project now. I'm using java build path. I added _javax.activation-api:1.2.0_ to external JARs, but that error still occurred ? – SuperBeam Oct 22 '18 at 04:35
  • @Andreas Do you mean that adding external lib is no meaning with java 11 ? Then, could you help me a more detail suggestion for solve this problem ? – SuperBeam Oct 22 '18 at 04:41
  • @Andreas I am aware of the fact that the *javax.activation:javax.activation-api:1.2.0 is not a module* and hence mentioned it as a dependency(just a way of depicting a complete artifact name). Could not relate to the question being asked in terms of framework in use earlier. And yes, in Java 11 the module is not there, but if you **explicitly** add the dependency and prefer to have a `module-info.java` in the project the `requires` is as valid as in Java 9.10. – Naman Oct 22 '18 at 04:48
  • @SuperBeam While you're executing the application where do you see the dependency being involved in? Is it present in the classpath? – Naman Oct 22 '18 at 04:51
  • @nullpointer I see the dependency on Properties of project (Java Build Path) of Eclipse. Is that true ? – SuperBeam Oct 22 '18 at 06:34
  • @nullpointer My point was that even ***if*** using modularised code, `requires java.activation` does not state a dependence on the *library*. Also, since question is about Java 11, not 9 or 10, adding `requires java.activation;` will actually cause a compilation error, so even mentioning it the way you do is misleading and confusing. If you had said "as an alternative to specifying dependency, in Java 9 and 10 you could ..." then mentioning it would be ok, but you didn't, so it makes the answer incorrect. – Andreas Oct 22 '18 at 09:13
  • @Andreas Could you please give me a suggestion correct answer relative in Java 11 ? – SuperBeam Oct 22 '18 at 09:33
  • The above error relate in JDK or Tomcat or Java 11 structure that are modularization ? – SuperBeam Oct 22 '18 at 09:41
  • @Andreas I'm sorry but I don't think this question is duplicate, I tried to convert my source code to use maven build but this error still appear. – SuperBeam Oct 24 '18 at 06:56
  • I believe developer should also add an implementation of this api, for example com.sun.activation:javax.activation:1.2.0 as a dependency (please, update your answer, if it's true). – kolobok Jan 29 '19 at 16:52
  • for gradle please add this compile 'javax.mail:mail:1.4.7' – asifaftab87 Apr 04 '21 at 02:04