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

重新运行即可!

相关推荐
程序员黄老师3 分钟前
VSCode 生成HTML 基本骨架
ide·vscode·html
mrbone118 分钟前
C++-C++中的几种cast
java·开发语言·c++
我爱Jack42 分钟前
Spring Boot 配置文件
java·数据库·spring boot
椰椰椰耶1 小时前
【redis】主从复制:单点问题、配置详解、特点详解
java·数据库·redis
阿汤哥的程序之路1 小时前
Java 安装开发环境(Mac Apple M1 Pro)
java·python·macos
齐 飞1 小时前
JVM类加载过程详解
java·jvm·笔记
big凉笙墨染1 小时前
《网络安全学习者必看!Java序列化与反序列化深度解读》
java·后端·安全
独行soc1 小时前
2025年渗透测试面试题总结-某华为面试复盘 (题目+回答)
java·python·安全·web安全·面试·职场和发展·红蓝攻防
neoooo1 小时前
Redis 缓存击穿、穿透、雪崩问题及解决方案
java·spring boot·redis
web150854159351 小时前
Windows操作系统部署Tomcat详细讲解
java·windows·tomcat