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

重新运行即可!

相关推荐
Grey Zeng7 小时前
Java SE 25新增特性
java·jdk·jdk新特性·jdk25
雨白8 小时前
Java 线程通信基础:interrupt、wait 和 notifyAll 详解
android·java
架构师沉默13 小时前
设计多租户 SaaS 系统,如何做到数据隔离 & 资源配额?
java·后端·架构
Java中文社群14 小时前
重要:Java25正式发布(长期支持版)!
java·后端·面试
每天进步一点_JL15 小时前
JVM 类加载:双亲委派机制
java·后端
用户2986985301416 小时前
Java HTML 转 Word 完整指南
java·后端
渣哥16 小时前
原来公平锁和非公平锁差别这么大
java
渣哥16 小时前
99% 的人没搞懂:Semaphore 到底是干啥的?
java
J2K16 小时前
JDK都25了,你还没用过ZGC?那真得补补课了
java·jvm·后端
kfyty72516 小时前
不依赖第三方,不销毁重建,loveqq 框架如何原生实现动态线程池?
java·架构