在我的一个项目中,我使用了以下依赖项:
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.2</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
具有以下
module-info.java
:
open module de.powerstat.fb.mini
{
exports de.powerstat.fb.mini;
requires transitive java.xml;
requires org.apache.logging.log4j;
requires transitive de.powerstat.validation;
requires transitive org.apache.httpcomponents.httpclient;
requires org.apache.httpcomponents.httpcore;
requires org.apache.commons.codec;
requires com.github.spotbugs.annotations;
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;
requires org.junit.platform.launcher;
requires org.junit.platform.suite.api;
}
我收到以下错误消息:
[INFO] --- surefire:3.5.0:test (default-test) @ miniapi ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[ERROR] Error occurred during initialization of boot layer
[INFO] Results:
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[WARNING] Corrupted channel by directly writing to native stream in forked JVM 1. See FAQ web page and the dump file C:\MyProject\target\surefire-reports\2024-09-28T15-18-12_539-jvmRun1.dumpstream
在上述文件中包含以下消息:
Stream 'Error occurred during initialization of boot layer'.
Stream 'java.lang.module.ResolutionException: Modules jdk.xml.dom and xercesImpl export package org.w3c.dom.html to module io.cucumber.core.gherkin.messages'.
在查看我的依赖项时,我发现:
jdk.xml.dom
:
org.w3c.dom.css
org.w3c.dom.html
org.w3c.dom.stylesheets
org.w3c.dom.xpath
以及:
xercesImpl-2.12.2.jar
:
org.apache.*
org.w3c.dom.html
这意味着我们这里有一个分割包,这在java模块系统中是不允许的。
有解决方法的想法吗?或者 xerces 可能无法与 java 模块系统一起使用? Saxon 会成为与 java 模块系统一起使用的替代品吗?或者还有其他解决办法吗?
感谢 Michael Kay 的提示,在使用较新的 Java 版本(如 17)时,似乎足以删除 xerces 依赖项:
<!--
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.2</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
-->