JDK 10 cannot import javax.xml.namespace in Eclipse
Asked Answered
M

6

14

It's very strange. I am moving a dynamic web project from Java 8 to Java 10.

The last thing I cannot get the dependency resolved is the javax.xml.namespace.QName class.

You can see in the attached screen shot, the QName class exist in JRE System Library, but the IDE keep complaining that QName cannot be resolved to a type. screen shot

Marella answered 9/10, 2018 at 10:44 Comment(4)
Why are you moving to Java 10 and not Java 11: java 10 is already EOL. According to the screenshot you have not imported things from the javax.xml.namespace package: do that first. In any case, post a minimal reproducible example, and specify whether you are also modularizing, as the javax.xml.* packages are in the module java.xml.Utilitarianism
I'm not understanding your concern. In your screenshot the very first quick fix proposed is: Import 'QName' (java.xml.namespace). If you select that quick fix then isn't your problem resolved? Or is the issue that you did select that quick fix, but QName remained unresolved? Either way, please update your post to explicitly state what happens after you select that quick fix to import QName. As it stands your question is unclear on this point.Laoag
Thanks for the comment and sorry that the screenshot is not clear. Actually if I select quick fix and import the class, the compiler still complaint that the class QName is not resolvableMarella
I have this same issue... My pom has it, and Eclipse sees it and will even find it with ctrl-space but it complains it can't be resolved to a type all the sameKrawczyk
M
22

There probably is a duplicate dependency pulled in from some other dependency.

In eclipse do

  1. "Navivate -> Open Type..."
  2. Type in "java.xml.namespace".
  3. If there are other results than from your (Open-)JDK, these need to be removed in the following steps. In my case it was xml-apis
  4. Open your pom.xml in eclipse, and visit the "Dependency Hierarchy" tab to check which dependency was pulling in xml-apis
  5. Type "xml-apis" in the Filter. In my case the top level dependency that was pulling xml-apis was "esapi"
  6. exclude xml-apis from the esapi dependency:

    <dependency>
        <groupId>org.owasp.esapi</groupId>
        <artifactId>esapi</artifactId>
        <version>2.2.0.0</version>
    
        <exclusions>
            <exclusion>
                <groupId>xml-apis</groupId>
                <artifactId>xml-apis</artifactId>
            </exclusion>
        </exclusions>
    
    </dependency>
    
  7. Right click your Project and choose "Maven -> Update Project...". Check your project and click OK.

That's it

Malina answered 23/4, 2020 at 12:51 Comment(0)
F
9

I had the same error moving from Java 8 to Java 11, and I included an explicit dependency on the library stax-api 1.0-2:

<dependency>
  <groupId>javax.xml.stream</groupId>
  <artifactId>stax-api</artifactId>
  <version>1.0-2</version>
</dependency>

and excluded any transitional dependency on the library stax-api 1.0.1:

    ...
    <exclusion>
      <groupId>stax</groupId>
      <artifactId>stax-api</artifactId>
    </exclusion>
    ...

After this, my IDE found the lost import javax.xml.namespace.QName correctly.

I hope this helps.

Franz answered 27/12, 2018 at 11:50 Comment(0)
I
7

Try to change the order of elements on your classpath. The JRE must be before the Maven Dependencies. That fixes the issue.

My guess is that the Java 10 compiler notices that you're trying to replace internal classes (java.xml.namespace) with code from JARs and it doesn't like that.

Imprecate answered 6/2, 2019 at 10:27 Comment(0)
C
2

I have had the same experience with the JRE 11, and Gradle 7.5. If it helps anyone, you can exclude xml-apis as such:

configurations {
    all {
        exclude group: 'xml-apis', module: 'xml-apis'
    }
}
Charette answered 6/10, 2022 at 14:26 Comment(0)
L
0

Resolved it by removing jsr173_api.jar from the project classpath (project -> properties -> java build path -> libraries -> classpath). It appears again when eclipse project rebuilt.

Lil answered 13/10, 2020 at 16:51 Comment(0)
A
0

This worked! Checking for multipletypes Ctrl+Shift+T, removing unwanted ones.

Arresting answered 14/4, 2021 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.