我正在使用JDK8迁移Java项目以使用JDK 11,然后发生了与javax激活有关的错误。 遵循Oracle的迁移指南,I see java.activation that module was removed from JDK 11.
之后,我建议添加第三方activation-1.0.2.jar *,但是仍然发生错误? 请提出有关问题的建议?能否告诉我有关从Java 8到Java 11的迁移经验(使用Tomcat 2018.09.4(4.9.0)的带有Tomcat 9.0.12的服务器)
这是详细信息错误:
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)
答案 0 :(得分:6)
您似乎包含了错误的工件(外部jar )。
您应将 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>
另外,请注意 如果 使用模块化代码(包括module-info.java
),则必须使用声明-
requires java.activation;