JDK 10 cannot import javax.xml.namespace in Eclipse

前端 未结 4 1792
孤街浪徒
孤街浪徒 2020-12-19 11:39

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 cl

相关标签:
4条回答
  • 2020-12-19 12:08

    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.

    0 讨论(0)
  • 2020-12-19 12:11

    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.

    0 讨论(0)
  • 2020-12-19 12:15

    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.

    0 讨论(0)
  • 2020-12-19 12:24

    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

    0 讨论(0)
提交回复
热议问题