0

[![enter image description here][1]][1]I am getting compilation error for classes refer to org.xml.sax and xml-apis using Eclipse 2019-03 and OpenJDK 11. I have deleted any maven dependency to xml-apis though it still shows in Maven repository and listed in Maven dependecies. I have set Maven dependencies before JDK in Order & export of project build path and vice versa but with no hope.

import org.xml.sax.*;
import org.xml.sax.ext.*;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.helpers.DefaultHandler;

I had to add the update here because of comment limited length:

Yes, I did checked Maven dependency hierarchy and found that Maven dependency

            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency> --> AND <!-- <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.9.1</version>
        </dependency> --> ```
includes xml-apis, I have commented that out both dependencies, but then I got compilation error to a class that refers to "org.apache.xerces.parsers.DOMParser" that I have to uncomment "xerces" dependency again and of course same problem happening because JDK have the classpath for java.xml which includes "org.w3.dom" and "rg.xml.sax"
[![enter image description here][2]][2]

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/m1li4.jpg
Telebh
  • 305
  • 1
  • 4
  • 13
  • 2
    The system library module `java.xml` contains the package `org.xml.sax.helpers` and therefore no JAR on the classpath (= `` module) is allowed also to contain the `org.xml.sax.helpers` package. In the Maven POM editor there is a tab _Dependencies Hierarchy_ where you can find out by which dependencies the JAR is required. By the way, your Eclipse is out-dated; you are two releases behind. – howlger Oct 03 '19 at 22:28
  • I have this hierarchy in Eclipse of JARS, 1st one from Maven dependency (which I even do not have it in POM file ?!) and 2nd one is from JDK. I have removed Maven dependency of "xml-apis-1.3.04" but still shows up in Maven dependency hierarchy. I have tried to compile same project in Eclipse 2019-09, still was same issue. xml-apis-1.3.04.jar org.xml.sax DocumentHandler.class SAXException.class .... jax-api-1.4.5.jar org.xml.sax DocumentHandler.class SAXException.class .... – Telebh Oct 04 '19 at 11:59
  • Your problem is that the `xml-apis-1.3.04.jar` is on the classpath, right? Did you use the _Dependencies Hierarchy_ tab of the POM editor? Did you update the Maven project after removing all dependencies with the XML APIs? Please show your POM. – howlger Oct 04 '19 at 12:31
  • Yes, I have checked Maven dependency hierarchy and found that dependency xerces xerces 1.4.0 includes 2 packages "org.w3c.dom" and org.xml.sax" so i commented this out but then compilation error in a class having this "org.apache.xerces.parsers.DOMParser" – Telebh Oct 04 '19 at 14:42
  • I have managed to exclude xml-apis-1.3.04.jar though I am not able to exclude sub-package "org.xml.sax" from maven dependency jar saxon saxon 6.5.2 – Telebh Oct 04 '19 at 19:39
  • 1
    What do you mean by sub-package? Make sure your Eclipse is up-to-date to avoid running into [long-fixed bugs like this one](https://stackoverflow.com/a/55592503/6505250). Otherwise, you have to get rid of the dependencies on your classpath or modulepath that contain a package that is already used in the system library to be able to use Java 9 or higher (see [for details here](https://stackoverflow.com/a/53824670/6505250)). In most cases, updating the dependencies is sufficient, since most current libraries are made to be used with Java 9 or higher. – howlger Oct 06 '19 at 08:41

1 Answers1

3

after checking Maven dependency hierarchy of pom file as suggested by @howlger I was able to find xerces has dependency on xml-apis, after excluding it, worked fine.

<dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.9.1</version>
            <exclusions>
            <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            </exclusion>
            </exclusions>
        </dependency>
Telebh
  • 305
  • 1
  • 4
  • 13