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'
}

重新运行即可!

相关推荐
沐浴露z1 分钟前
【JVM】详解 对象的创建
java·jvm
weixin_445476684 分钟前
Java并发编程——提前聊一聊CompletableFuture和相关业务场景
java·并发·异步
ChinaRainbowSea5 分钟前
11. Spring AI + ELT
java·人工智能·后端·spring·ai编程
不会写DN5 分钟前
用户头像文件存储功能是如何实现的?
java·linux·后端·golang·node.js·github
聪明的笨猪猪12 分钟前
Java JVM “类加载与虚拟机执行” 面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
盖世英雄酱5813613 分钟前
FullGC排查,居然是它!
java·后端
老K的Java兵器库22 分钟前
集合性能基准测试报告:ArrayList vs LinkedList、HashMap vs TreeMap、并发 Map 四兄弟
java·开发语言
Knight_AL26 分钟前
如何解决 Jacob 与 Tomcat 类加载问题:深入分析 Tomcat 类加载机制与 JVM 双亲委派机制
java·jvm·tomcat
哲学七39 分钟前
Springboot3.5.x版本引入javaCv相关库版本问题以及精简引入包
java·ffmpeg