迁移到 JDK 11 时出现错误“java.lang.NoClassDefFoundError: javax/activation/DataSource”(tomcat 9.0.12)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52921879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Migration to JDK 11 has error occure "java.lang.NoClassDefFoundError: javax/activation/DataSource" (tomcat 9.0.12)
提问by SuperBeam
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.
我正在迁移 java 项目使用 JDK8 以使用 JDK 11 然后发生了与 javax 激活相关的错误。按照 Oracle 的迁移指南,我看到 java.activation 模块已从 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)
之后,我建议添加第三方**activation-1.0.2.jar*,但仍然出现错误?请就问题提出建议?你能告诉我迁移源代码使用 Java 8 到 Java 11 的经验吗(带有 tomcat 9.0.12 的服务器。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)
回答by Naman
You seem to have included an incorrect artifact(external jar).
您似乎包含了一个不正确的工件(外部 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:
您应该包含javax.activation:javax.activation-api:1.2.0
作为项目的外部依赖项以显式访问该类javax.activation.DataSource
。相同的示例 maven 依赖项将是:
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
Also, note ifusing modularised code (includes module-info.java
), you must state a dependence on the library using declaration -
另外,请注意,如果使用模块化代码(包括module-info.java
),则必须使用声明声明对库的依赖 -
requires java.activation;