idea插件开发dom4j报错:SAXParser cannot be cast to class org.xml.sax.XMLReader

手打不易,如果转摘,请注明出处!

注明原文: https://blog.csdn.net/q258523454/article/details/145512328


dom4j报错

idea插件使用到了dom4j依赖,但是报错:

I will print the stack trace then carry on using the default SAX parser

Caught exception attempting to use SAX to load a SAX XMLReader

java.lang.ClassCastException: class org.apache.xerces.parsers.SAXParser cannot be cast to class org.xml.sax.XMLReader (org.apache.xerces.parsers.SAXParser is in unnamed module of loader com.intellij.util.lang.PathClassLoader @5ba23b66; org.xml.sax.XMLReader is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @63326c11)

复制代码
I will print the stack trace then carry on using the default SAX parser
Caught exception attempting to use SAX to load a SAX XMLReader 
java.lang.ClassCastException: class org.apache.xerces.parsers.SAXParser cannot be cast to class org.xml.sax.XMLReader (org.apache.xerces.parsers.SAXParser is in unnamed module of loader com.intellij.util.lang.PathClassLoader @5ba23b66; org.xml.sax.XMLReader is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @63326c11)

原因

这是因为依赖冲突了,IntelliJ IDEA 新版已经自带了

<dependency>

<groupId>xml-apis</groupId>

<artifactId>xml-apis</artifactId>

<version>xxx</version>

</dependency>

解决

我们只需要排除这个依赖即可

build.gradle 文件中添加(新版gradle):

复制代码
configurations.configureEach {
    exclude group: 'xml-apis', module: 'xml-apis'
}

或者(旧版本gradle)

复制代码
configurations.all {
    exclude group: 'xml-apis', module: 'xml-apis'
}

重新运行即可!

相关推荐
tryxr2 分钟前
ReentrantLock 与 synchronized 的区别
java··reentrantlock
Java爱好狂.30 分钟前
Java面试Redis核心知识点整理!
java·数据库·redis·分布式锁·java面试·后端开发·java八股文
sheji341640 分钟前
【开题答辩全过程】以 基于Java的应急安全学习平台的设计与实现为例,包含答辩的问题和答案
java·开发语言·学习
程序员小假1 小时前
我们来说一下消息的可靠性投递
java·后端
席之郎小果冻1 小时前
【04】【创建型】【聊一聊,建造者模式】
java·前端·建造者模式
原来是好奇心1 小时前
深入Spring Boot源码(四):Starter机制与依赖管理深度解析
java·源码·springboot·starter
阿杆1 小时前
如何在 Spring Boot 中接入 Amazon ElastiCache
java·数据库·redis
cheems95271 小时前
锁策略的介绍
java·开发语言
武子康1 小时前
Java-199 JMS Queue/Topic 集群下如何避免重复消费:ActiveMQ 虚拟主题与交付语义梳理
java·分布式·消息队列·rabbitmq·activemq·mq·java-activemq