简体   繁体   English

package org.w3c.dom 可以从多个模块访问:<unnamed> , java.xml</unnamed>

[英]The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml

I am unable to import org.w3c.dom.NodeList package to Eclipse.我无法将org.w3c.dom.NodeList package 导入 Eclipse。 It is showing它正在显示

The package org.w3c.dom is accessible from more than one module: <unnamed> , java.xml" error message in eclipse. package org.w3c.dom 可从多个模块访问: <unnamed> , java.xml" Z6B7B655DD22FAA3F10677C512493A8A 中的错误消息

Please let me know how to fix this?请让我知道如何解决这个问题?

Eclipse Version: Eclipse 版本:

Eclipse IDE for Enterprise Java Developers. Eclipse IDE 适用于企业 Java 开发人员。

Version: 2019-06 (4.12.0)版本:2019-06 (4.12.0)

Build id: 20190614-1200版本号:20190614-1200

Java version: Java版本:

java version "12.0.1" 2019-04-16 java 版本“12.0.1” 2019-04-16

Java(TM) SE Runtime Environment (build 12.0.1+12) Java(TM) SE 运行时环境 (build 12.0.1+12)

Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing) Java HotSpot(TM) 64位服务器虚拟机(build 12.0.1+12,混合模式,共享)

I had a similar issue because of a transitive xml-apis dependency.由于可传递的xml-apis依赖关系,我遇到了类似的问题。 I resolved it using a Maven exclusion:我使用 Maven 排除解决了它:

<dependency>
    <groupId>org.apache.xmlgraphics</groupId>
    <artifactId>fop</artifactId>
    <version>0.95</version>
    
    <exclusions>
        <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Another dependency that just causes trouble and I don't have a solution other than removing it is this one:另一个只会引起麻烦的依赖项,除了删除它之外我没有其他解决方案是这个:

<dependency>
    <groupId>com.oracle.database.xml</groupId>
    <artifactId>xmlparserv2</artifactId>
    <version>${oracle.version}</version>
</dependency>

Use mvn dependency:tree to see who brings in the transitive dependency, and then exclude that from there.使用mvn dependency:tree查看谁引入了传递依赖,然后从那里排除。

Disappointingly I don't see any compiler flags to show what jar the problem is with Even -Xlint:module doesn't seem to show up anything useful and eclipse doesn't shed any light on the issue令人失望的是,我没有看到任何编译器标志来显示问题是什么 jar 甚至 -Xlint:module 似乎没有显示任何有用的东西,而且 eclipse 也没有说明这个问题

Instead to find where org.w3c.dom comes from I've been using this script:而不是找到 org.w3c.dom 从哪里来,我一直在使用这个脚本:

mvn dependency:copy-dependencies -DincludeScope=test -DoutputDirectory=deps
for i in deps/*.jar; do if unzip -l $i| grep -q org.w3c.dom; then echo $i; fi ; done

Strictly you don't have to specify the scope test as that's the default but I've included it as you might want to use compile instead严格地说,您不必指定范围测试,因为这是默认设置,但我已将其包含在内,因为您可能想改用compile

On my side, I've spent a few hours to understand my issue, really closed to this one.在我这边,我花了几个小时来了解我的问题,对这个问题真的很接近。
The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml

I wanted to migrate a project from Java 8 to Java 11. A few library issues.我想将一个项目从 Java 8 迁移到 Java 11。一些库问题。 Easy to fix.易于修复。 But on this one,但在这一点上,

  • I've tried to create module-info.java → it was worst.我试图创建 module-info.java → 最糟糕。
  • Find a issue on my OS (debian 10) → even if Java 11 was default JRE, $JAVA_HOME was not rightly set for maven build.在我的操作系统 (debian 10) 上发现问题 → 即使 Java 11 是默认的 JRE,$JAVA_HOME 也没有正确设置为 maven 构建。 And when I was thinking it was only an Eclipse issue, I finally consider that it was a global compilation problem.而当我认为这只是一个 Eclipse 问题时,我最终认为这是一个全局编译问题。 To fix this I had to add following line in ~/.mavenrc为了解决这个问题,我必须在~/.mavenrc添加以下行

    JAVA_HOME=/usr/lib/jvm/default-java

  • Deep analysis on maven dependencies shows me a third-level dependency on xom .jar which trigger the issue.对 maven 依赖项的深入分析显示我对xom .jar 的第三级依赖项触发了该问题。 Dependency was linked to Saxon HE library → an upgrade to VERSION 9.9.X has resolved this boring problem.依赖被链接到Saxon HE库 → 升级到版本 9.9.X解决了这个无聊的问题。

Hope this will helps other people.希望这会帮助其他人。

In my case, it was caused by combining the usage of:在我的情况下,它是由组合使用引起的:

  • JDK 11
  • dom4j 2.1.3 library dom4j 2.1.3

As pointed out by others, the root cause is that dom4j and its dependencies (eg, pull-parser ) use some packages names ( javax.xml.parsers , org.w3c.dom ) that have been used by the JDK.正如其他人指出的那样,根本原因是dom4j及其依赖项(例如, pull-parser )使用了一些 JDK 使用的包名称( javax.xml.parsersorg.w3c.dom )。

I had to remove dom4j to solve the problem.我不得不删除dom4j来解决这个问题。 Just use JDK's own XML api.只需使用 JDK 自己的 XML api。

For Java 9 and higher Delete org.w3c.dom jar file from the class path, and you are done.对于 Java 9 及更高版本,从类路径中删除 org.w3c.dom jar 文件,您就完成了。 By the way delete module info file too.顺便删除模块信息文件。 You don't need to add the external jar file, its already included in the system library of java 9 and higher.您不需要添加外部 jar 文件,它已经包含在 java 9 及更高版本的系统库中。

Just open the configure build path and verify the modules which are all you have added as part of the project, which contains the class files as *只需打开配置构建路径并验证您作为项目一部分添加的所有模块,其中包含类文件 *

org.w3c.dom org.w3c.dom

This error, we usually gets in Java due to same kind of multiple API packages added in one project.这个错误,我们通常在Java中由于在一个项目中添加了相同类型的多个API包而出现。

As, am using the same version as you mentioned, am not facing any issues., so just make sure that you don't have any duplicate modules.因为,我使用的版本与您提到的相同,所以没有遇到任何问题,所以请确保您没有任何重复的模块。

In my case I was using:就我而言,我使用的是:
JDK 14 and xmlbeans.jar library. JDK 14xmlbeans.jar库。
I just had to remove the xmlbeans.jar library and it surely solved the issue.我只需要删除xmlbeans.jar库,它肯定解决了这个问题。

org.w3c.dom is used in: org.w3c.dom用于:

<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>2.4.0</version>
</dependency>

Check if this is imported transitively via some other dependency.检查这是否是通过其他一些依赖项传递导入的。 Exclude the same排除相同

Add dependency for:添加依赖项:

<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>2.6.0</version>
</dependency>

I am unable to import org.w3c.dom.NodeList package to Eclipse.我无法将org.w3c.dom.NodeList包导入 Eclipse。 It is showing它正在显示

The package org.w3c.dom is accessible from more than one module: <unnamed> , java.xml" error message in eclipse.包 org.w3c.dom 可以从多个模块访问: <unnamed> , java.xml" eclipse 中的错误消息。

Please let me know how to fix this ?请让我知道如何解决这个问题?

Eclipse Version:日蚀版:

Eclipse IDE for Enterprise Java Developers.面向企业 Java 开发人员的 Eclipse IDE。

Version: 2019-06 (4.12.0)版本:2019-06 (4.12.0)

Build id: 20190614-1200版本号:20190614-1200

Java version:爪哇版:

java version "12.0.1" 2019-04-16 java版本“12.0.1” 2019-04-16

Java(TM) SE Runtime Environment (build 12.0.1+12) Java(TM) SE 运行时环境(构建 12.0.1+12)

Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing) Java HotSpot(TM) 64 位服务器 VM(构建 12.0.1+12,混合模式,共享)

If you are in a simple Java Project , not Maven.如果您在一个简单的Java 项目中,而不是 Maven。 Then just remove the dom-jaxb jar from the Libraries.然后只需从库中删除 dom-jaxb jar

Steps : Right click on project -> Properties -> Java BuildPath -> Libraries Tab -> select on jars such as dom-2.3.0-jaxb-1.0.6(version might differ) -> Remove.步骤:右键单击项目 -> 属性 -> Java BuildPath -> 库选项卡 -> 选择 jars,例如 dom-2.3.0-jaxb-1.0.6(版本可能不同)-> 删除。

Now it will build without error.现在它将构建而不会出错。

The error is occurring because "org.w3c.dom.Document" is coming from both the removed "dom-2.3.0-jaxb-1.0.6" jar and from Java's in-built libraries.发生错误是因为“org.w3c.dom.Document”来自已删除的“dom-2.3.0-jaxb-1.0.6”jar 和 Java 的内置库。 Removing additional jar will let it come only from Java's in-built libraries.删除额外的 jar 将让它只来自 Java 的内置库。

You need to manually check and remove all the jars (libraries) which has the possibility of conflicting with java.xml package.您需要手动检查并删除所有可能与java.xml包冲突的 jar(库)。

In my case, I edited my .classpath file and removed the following jars and it resolved the issue:就我而言,我编辑了.classpath文件并删除了以下 jars 并解决了问题:

jtidy.jar, castor-0.9.5.4-xml.jar, xercesImpl.jar, xml-apis.jar

In my case, culprit was Apache POI library.就我而言,罪魁祸首是 Apache POI 库。 Added exclusion as below添加排除如下

<!-- Apache POI Library for Parsing Excel Sheets -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>5.0.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.xmlbeans</groupId>
                <artifactId>xmlbeans</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

You can use this code (for example in a unit test) to determine all JARs that contain a class:您可以使用此代码(例如在单元测试中)确定所有包含 class 的 JARs:

getClass().getClassLoader().getResources("org/w3c/dom/NodeList.class");

This gives you an Enumeration .这给了你一个Enumeration The easiest way to print this is:最简单的打印方法是:

Collections.list(e).forEach(System.out::println);

In a Gradle land, you can track down which dependencies are contributing to xml-api s by running:在 Gradle 土地中,您可以通过运行以下命令来跟踪哪些依赖项对xml-api有贡献:

gradlew -q dependencies

(or core:dependencies for the core project in a multi-project environment). (或核心:多项目环境中core项目的core:dependencies项)。

In my case, xml-apis was being requested by both net.sourceforge.htmlunit and xom , so the solution is to exclude xml-apis in your build.gradle as so:就我而言, net.sourceforge.htmlunitxom都请求了xml-apis ,因此解决方案是在您的build.gradle中排除xml-apis

dependencies {
  implementation("net.sourceforge.htmlunit:neko-htmlunit:$nekoHtmlUnitVersion") {
    exclude group: "xml-apis"
  }
  testImplementation("xom:xom:$xomVersion") {
    exclude group: "xml-apis"
  }
  // ...other dependencies
}

Sometimes even when you have removed duplicate classes the same error "The package org.w3c.dom is accessible from more than one module" may remain, especially with IDEs.有时即使您删除了重复的类,同样的错误“package org.w3c.dom可以从多个模块访问”可能仍然存在,尤其是对于 IDE。

IT IS NOT always enought to find only org.w3c.dom ..,.只找到 org.w3c.dom 并不总是足够的..,。 You may need to remove duplicate classes which share the same parent package org.w3c.xxx, for example org.w3c.css您可能需要删除共享相同父 package org.w3c.xxx 的重复类,例如 org.w3c.css

We managed to fix it like this:我们设法像这样修复它:

  • In IDE search classes starting with: org.w3c在 IDE 搜索类开头:org.w3c
  • Add pom.xml exclusions or increase library version, since org.w3c has been removed in some newer lib versions添加 pom.xml 排除项或增加库版本,因为 org.w3c 在一些较新的库版本中已被删除
  • Test compile in both IDE and command line在 IDE 和命令行中测试编译

If the issue persists:如果问题仍然存在:

  • Export all dependencies to file: mvn dependency:copy-dependencies -DincludeScope=test -DoutputDirectory=deps将所有依赖项导出到文件: mvn dependency:copy-dependencies -DincludeScope=test -DoutputDirectory=deps
  • From jar-files find any classes of org.w3c从 jar 文件中找到 org.w3c 的任何类
  • Keep adjusting pom.xml继续调整pom.xml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 关于“可以从多个模块访问包 org.w3c.dom 的具体问题:<unnamed> ,java.xml&quot; - Specific question concerning "The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml" package org.w3c.dom 可以从多个模块访问:<unnamed> , java.xml ~ 查找和排除依赖</unnamed> - The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml ~ Find and exclude dependency 排除依赖无助于修复“package org.w3c.dom 可以从多个模块访问:<unnamed> , java.xml”</unnamed> - Excluding dependency does not help to fix “The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml” 包 javax.xml.stream 可以从多个模块访问:<unnamed> , java.xml - The package javax.xml.stream is accessible from more than one module: <unnamed>, java.xml package javax.xml.namespace 可以从多个模块访问:<unnamed> , eclipse 网络服务中的 java.xml</unnamed> - The package javax.xml.namespace is accessible from more than one module: <unnamed>, java.xml in eclipse webservice 可从多个模块访问的包:<unnamed> - Package accessible from more than one module: <unnamed> 春季启动2。Java10。JUnit。 可以从多个模块中访问org.slf4j软件包: <unnamed> ,slf4j.api - Spring boot 2. Java 10. JUnit. The package org.slf4j is accessible from more than one module: <unnamed>, slf4j.api 在XML org.w3c.dom中阅读特殊字符 - Reading special Charanters in XML org.w3c.dom 为什么org.w3c.dom解析我的xml错误? - Why is org.w3c.dom parsing my xml wrong? Java org.w3c.dom:有一个Java解析器库吗? - Java org.w3c.dom : is there a Java parser library?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM