3

I am migrating my project from java 8 to openJDK 11. In my code I use the classes

import com.sun.org.apache.xml.internal.dtm.DTM;
import com.sun.org.apache.xml.internal.dtm.DTMManager;
import com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM;
import com.sun.org.apache.xml.internal.utils.XMLStringFactory;
import com.sun.org.apache.xpath.internal.objects.XMLStringFactoryImpl

I am using eclipse. I am getting the error that the types are not accessible. I also tried this post with the last import How to tell eclipse to add-exports when compiling

But it did not work. Any idea how could we fix this? Does the error mean that the packages have become internal and should be replaced in the code?

Rasha Elsayed
  • 660
  • 1
  • 7
  • 22
  • 2
    This is exactly why you are advised against using vendor specific classes explicitly because they can change or go away without warning. Bring in your own copy of the library. – Thorbjørn Ravn Andersen Sep 29 '19 at 14:44
  • What do you mean by "Bring in your own copy of the library"? – Rasha Elsayed Sep 30 '19 at 09:31
  • 2
    `com.sun.org.apache.xml` is how Sun imported existing third-part libraries in the Java runtime. Change their package so it didn't clash with a user-provided `org.apache.xml` package (most likely Xerces). Remove these imports, bring in a suitable version of Xerces, and let your IDE help reimporting. – Thorbjørn Ravn Andersen Sep 30 '19 at 09:44

3 Answers3

2

I had a similar issue where I needed to update a reference to com.sun.org.apache.xml.internal.serializer.OutputPropertiesFactory, and found I could change it to:

import org.apache.xml.serializer.OutputPropertiesFactory;

if I included the right Xalan apache xml dependency:

        <dependency>
            <groupId>xalan</groupId>
            <artifactId>xalan</artifactId>
            <version>2.7.2</version>
        </dependency>
Sean
  • 2,315
  • 20
  • 25
1

In openJdk11 you have to import xml-security.jar ( com.sun.org.apache.xml is not present so you have to)

Fred
  • 33
  • 5
0

Trying this solved my problem: import java.net.URI;

I had the same issue while trying

URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").
                buildAndExpand(savedUser.getId()).toUri();

in JDK 11. When I tried the recommended imports(import com.sun.org.apache.xerces.internal.util.URI, import com.sun.org.apache.xml.internal.utils.URI). I got the same error.

Procrastinator
  • 2,526
  • 30
  • 27
  • 36