本文介绍了JDK 9:使用SpringExtension编译的JUnit 5测试产生java.lang.NoClassDefFoundError:org/w3c/dom/ls/DocumentLS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信此问题与JDK 9中的模块排除(与java.se.ee无关)有关,而是与JDK 9包括更新版本的 org.w3c.dom.ls 没有DocumentLS类的"http://download.java.net/java/jdk9/docs/api/java.xml-summary.html" rel ="noreferrer"> java.xml 模块.

I believe this problem not to be related to module exclusions in JDK 9 (as with java.se.ee), but rather with the fact that JDK 9 includes a newer version of org.w3c.dom.ls in the java.xml module that does not have the DocumentLS class.

堆栈跟踪的重要部分是:

The important bit of the stack trace is this:

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [spring-test/test-container.xml]; nested exception is java.lang.NoClassDefFoundError: org/w3c/dom/ls/DocumentLS
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:414)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)

即使我在此类中包含运行时依赖项(例如xerces:xerces 2.4.0),还是首选JDK java.xml模块.(我想).

Even if I include a runtime dependency with this class, like xerces:xerces 2.4.0, the JDK java.xml module is preferred (I guess).

我正在使用Gradle 4.1.有没有办法限制范围JDK提供的模块?

I am using Gradle 4.1. Is there any way to restrict the scope of aJDK provided module?

推荐答案

经正确分析,包org.w3c.dom.ls存在于平台模块 java.xml .在同一个包中的类路径上的任何类都将被忽略.这就是一个拆分包 存在多个修补程序-接下来的两个步骤可能会对您有所帮助.

As you have correctly analyzed, the package org.w3c.dom.ls is present in the platform module java.xml. Any class on the class path that is in the same package will be ignored. That's called a split package and several fixes exist - the following two might help you.

您可以使用java.xml 模块中. -to-hack-the-java-9-module-system/#Adding-Classes-To-Modules-With--patch-module"rel =" nofollow noreferrer> --patch-module :

You can add the classes of the Xerxes JAR to the java.xml module with --patch-module:

java --patch-module java.xml=xerxes-4.0.0.jar ...

我从未尝试过使用包含某些相同类的JAR.据我了解,JDK类将被Xerxes类替换,这意味着它们最好是完全二进制兼容的替换.

I've never tried that with a JAR that contains some of the same classes. As I understand it, the JDK classes will then be replaced with the Xerxes classes, which means they better be a fully binary compatible replacement.

另一个希望是将 java.xml 替换为升级模块路径:

Another hope is to replace java.xml with the upgrade module path:

您面临两个问题:

  • 升级模块路径应该仅用于可升级模块(不是 java.xml ),但是我想我已经读到了未执行的地方(还好吗?)–没有不要尝试
  • java.xml 替换的工件需要完全二进制兼容的更新-Xerxes会是这种情况吗?
  • the upgrade module path is supposed to be used only for upgradable modules (which java.xml is not), but I think I've read somewhere that that's not enforced (yet?) - didn't try it
  • the artifact you replace java.xml with needs to be fully binary compatible update - would that be the case for Xerxes?

这篇关于JDK 9:使用SpringExtension编译的JUnit 5测试产生java.lang.NoClassDefFoundError:org/w3c/dom/ls/DocumentLS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:42