Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. It is showing

The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml" error message in eclipse.

Please let me know how to fix this ?

Eclipse Version:

Eclipse IDE for Enterprise Java Developers.

Version: 2019-06 (4.12.0)

Build id: 20190614-1200

Java version:

java version "12.0.1" 2019-04-16

Java(TM) SE Runtime Environment (build 12.0.1+12)

Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

like image 854
poovaraj Avatar asked Jul 31 '19 08:07

poovaraj


People also ask

What is org w3c DOM document?

Package org. w3c. dom Description. Provides the interfaces for the Document Object Model (DOM) which is a component API of the Java API for XML Processing. The Document Object Model Level 2 Core API allows programs to dynamically access and update the content and structure of documents.


2 Answers

I had a similar issue because of a transitive xml-apis dependency. I resolved it using a Maven exclusion:

<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.

like image 57
Lukas Eder Avatar answered Sep 18 '22 21:09

Lukas Eder


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

Instead to find where org.w3c.dom comes from I've been using this script:

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

like image 29
MSillence Avatar answered Sep 16 '22 21:09

MSillence