XML-api.jar classes having issues with JAVA 11 in EClipse 4.9

user3820339 picture user3820339 · Dec 11, 2018 · Viewed 9.2k times · Source

org.xml.sax and org.w3c.dom classes are not working with JAVA 11 and Eclipse Photon 4.9 & 4.10 RC2 build

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

import org.xml.sax.DocumentHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.AttributeList;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;

enter image description here

enter image description here

These class imports from the org.w3c.dom & org.xml.sax are not working with Eclipse SDK

Version: 2018-09 (4.9) Build id: I20180906-0745

Problem Description :

Post import of the project in eclipse workspace (Downloaded the JAVA 11 compatible Eclipse 4.9 version.), this start giving error during compilation for these classes.

This error goes away if you simply use

import org.xml.sax.*;
import org.w3c.dom.*; 

instead of usual complete package name. But this only gets away the error but doesn't help completely. So If we go further and want to use and import any particular specific classes from the sax or w3c , it will not give option and you cannot even make explicit import. SO this approach is of no use.

Another workaround is, if we place the JRE System Library (JAVA 11) above in order & export section of configure buildpath option of ECLIPSE workspace, then these import errors go away.

xml-apis.jar

But this is only happening if we compile using the JAVA 11 through compiler of Eclipse. If we switch back to JAVA 8 compiler in eclipse then same combination works fine.

This issue happens with JAVA 9 also.

Could someone please help resolving this?

There is already an Eclipse bug filed but it has not yet any resolution : https://bugs.eclipse.org/bugs/show_bug.cgi?id=536928#c12

enter image description here

Answer