JDK 10 cannot import javax.xml.namespace in Eclipse

夙愿已清 提交于 2020-01-24 18:00:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!