3

I am trying to migrate my application from Java 8 to Open JDK 11.

In which few of the imports are missing in JDK 11. For example I could not find below imports

import org.w3c.dom.Document;
import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;
import org.xml.sax.SAXException;

But when i tired to add external jar for (w3c-dom.jar), we are getting the below error

The package org.w3c.dom is accessible from more than one module: , java.xml

As like the above, same error is occurring for all the imports

The package org.xml.sax is accessible from more than one module: , java.xml

Please suggest your views on the above error.

Karthick88it
  • 601
  • 2
  • 12
  • 28
  • 1
    Are you using eclipse , if yes pls refer - https://stackoverflow.com/questions/51094274/eclipse-cant-find-xml-related-classes-after-switching-build-path-to-jdk-10/51094559 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=544758 – Ramesh Subramanian May 10 '19 at 07:06
  • Yes Ramesh, I am using Eclipse IDE. I have tried changing the JRE order in the class path but no luck. – Karthick88it May 10 '19 at 07:09
  • In addition, I have tried using "xml-apis-2.0.jar" and my JDK is in the top of the classpath. – Karthick88it May 10 '19 at 07:14
  • 1
    Seems it is a bug in the eclipse. Here is a long discussion about the bug - https://bugs.eclipse.org/bugs/show_bug.cgi?id=536928 – Ramesh Subramanian May 10 '19 at 07:26
  • Thanks Ramesh. I am currently using eclipse Version: 2019-03 (4.11.0). Let me try for other version – Karthick88it May 10 '19 at 09:32

1 Answers1

4

I faced similar issue, like mentioned below.

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

Because there was a dependency which internally generating xml-apis.jar, and this jar was actually created the problem. I followed below mentioned steps and it helped me.

  • Go to .m2 repository folder of your system and check if xml-apis.jar is present, if yes it means this jar is creating problem.
  • Delete this jar from repository folder.
  • And exclude the xml-apis transitive dependency in your pom.xml.
  • Refresh, recompile project and check.

Note: It may be a different dependency in your case which generates this xml-api.jar, so find that dependency and exclude xm-api.

enter image description here

Ashu Phaugat
  • 632
  • 9
  • 23