11

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

greg-449
  • 109,219
  • 232
  • 102
  • 145
Ivan
  • 417
  • 1
  • 4
  • 10
  • 3
    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 [mcve], and specify whether you are also modularizing, as the javax.xml.* packages are in the module java.xml. – Mark Rotteveel Oct 09 '18 at 12:56
  • 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. – skomisa Oct 09 '18 at 22:10
  • 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 resolvable – Ivan Oct 11 '18 at 23:26
  • 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 same – chrislhardin Oct 22 '18 at 10:17

6 Answers6

16

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

lilalinux
  • 2,903
  • 3
  • 43
  • 53
8

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.

Wagner Lopes
  • 81
  • 1
  • 5
6

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.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
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.

Asanka
  • 83
  • 1
  • 7
0

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

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
0

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'
    }
}
Patrice Gagnon
  • 1,276
  • 14
  • 14