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

重新运行即可!

相关推荐
是小蟹呀^7 小时前
Spring Security + JWT 面试题整理
java·jwt·springsecurity
spencer_tseng10 小时前
Redis + Nacos.bat
java·windows·dos
troyzhxu10 小时前
列表查询的 GraphQL —— 一行代码终结你的 if-else 地狱!
java·springboot·graphql
孫治AllenSun11 小时前
【DataX】生产环境搭建DataX集群案例
java·开发语言·jvm
好好沉淀12 小时前
@NotBlank(message = “{xxx}“) 注解中花括号的含义
java
fīɡЙtīиɡ ℡12 小时前
内存泄漏产生的原因
java·spring·servlet
hkj880812 小时前
Ubuntu 切换java版本
java·linux·ubuntu
码智社13 小时前
Java实现RSA密钥生成、加密解密、加签验签
java
wear工程师13 小时前
ThreadLocal 在线程池里为什么会串数据:别只会答内存泄漏
java·后端