问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/52719125/jdk-10-cannot-import-javax-xml-namespace-in-eclipse