XML-api.jar和org.xml.sax类在JAVA 11中有问题

问题描述 投票:0回答:1

[![在此处输入图像描述] [1]] [1]我正在使用Eclipse 2019-03和OpenJDK 11引用org.xml.sax和xml-apis的类出现编译错误。我已经删除了任何maven依赖项到xml-apis,尽管它仍显示在Maven存储库中并列在Maven依赖中。在JDK之前,我已经在项目构建路径的Order&export中设置了Maven依赖关系,反之亦然,但是没有希望。

import org.xml.sax.*;
import org.xml.sax.ext.*;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.helpers.DefaultHandler;

由于评论长度有限,我不得不在此处添加更新:

是的,我检查了Maven依赖关系层次结构,发现该Maven依赖关系

            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency> --> AND <!-- <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.9.1</version>
        </dependency> --> ```
includes xml-apis, I have commented that out both dependencies, but then I got compilation error to a class that refers to "org.apache.xerces.parsers.DOMParser" that I have to uncomment "xerces" dependency again and of course same problem happening because JDK have the classpath for java.xml which includes "org.w3.dom" and "rg.xml.sax"
[![enter image description here][2]][2]

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/m1li4.jpg
eclipse sax
1个回答
0
投票

按照@howlger的建议检查了pom文件的Maven依赖关系层次结构后,我发现xerces对xml-apis具有依赖关系,排除它之后,效果很好。

<dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.9.1</version>
            <exclusions>
            <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            </exclusion>
            </exclusions>
        </dependency>
© www.soinside.com 2019 - 2024. All rights reserved.