[英]Excluding dependency does not help to fix “The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml”
When trying to setup a project with a Java version > 9 I came across a problem with dependencies and the Java module system.在尝试使用 Java 版本 > 9 设置项目时,我遇到了依赖项和 Java 模块系统的问题。 I know that there are some posts regarding this topic (eg this one or this one ), but the solutions (exclude packages from dependencies) don't seem to help in my case.我知道有一些关于这个主题的帖子(例如this one或this one ),但解决方案(从依赖项中排除包)似乎对我没有帮助。
On some imports related to XML parsing, I get the following error The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml
On some imports related to XML parsing, I get the following error The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml
I used the "Open Type" dialog and found that there are in fact two providers for eg org.w3c.dom.Document.我使用了“打开类型”对话框,发现实际上有两个提供程序,例如 org.w3c.dom.Document。
This rmlmapper-4.9.1.jar is currently the only maven dependency in my project and I tried to exclude xml-apis as suggested here .这个rmlmapper-4.9.1.jar目前是我项目中唯一的 maven 依赖项,我尝试按照此处的建议排除 xml-apis。 I also added org.w3c.dom as you can see.如您所见,我还添加了 org.w3c.dom。
<dependencies>
<dependency>
<groupId>be.ugent.rml</groupId>
<artifactId>rmlmapper</artifactId>
<version>4.9.1</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>org.w3c</groupId>
<artifactId>dom</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Unfortunately, this doesn't help and the error persists.不幸的是,这无济于事,错误仍然存在。 Note that I can build the project but get errors at runtime.请注意,我可以构建项目,但在运行时会出错。 Am I excluding the wrong packages?我是否排除了错误的包裹? I couldn't find a package providing org.w3c.dom
using mvn dependency:tree
so how can I find the packages that need to be excluded?我找不到使用mvn dependency:tree
提供org.w3c.dom
的 package 那么如何找到需要排除的包?
From the Eclipse snapshot you provide, it seems the package org.w3c.dom
is embedded in the rmlmapper
dependency Jar itself (the Jar is probably bundling its own dependencies in it). From the Eclipse snapshot you provide, it seems the package org.w3c.dom
is embedded in the rmlmapper
dependency Jar itself (the Jar is probably bundling its own dependencies in it). Therefore the exclusion
will not work as it only excludes transitive dependencies (not bundled packages).因此exclusion
将不起作用,因为它只排除传递依赖项(而不是捆绑包)。 Even though it's possible to exclude the package , another approach is to exclude the java.xml
module with the --limit-modules
option as answered here .即使可以排除 package ,另一种方法是排除java.xml
模块, 这里回答了--limit-modules
选项。 Note that you might have to do this with other modules if rmlmapper
also bundles other JDK classes.请注意,如果rmlmapper
还捆绑了其他 JDK 类,您可能必须对其他模块执行此操作。
Either way, the best solution is to contact the owner of the rmlmapper
library and let them know of the issue on Java 9+, as maybe they did not upgrade their project to support that version.无论哪种方式,最好的解决方案是联系rmlmapper
库的所有者,让他们知道 Java 9+ 上的问题,因为他们可能没有升级他们的项目以支持该版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.