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

重新运行即可!

相关推荐
cui_hao_nan35 分钟前
Prompt‏ 工程和优化技巧
java·prompt
至善迎风1 小时前
Windows系统中如何使用符号链接将.vscode等配置文件夹迁移到D盘(附 CMD & PowerShell 双版本命令)
ide·windows·vscode
miachen-空中飞鸟1 小时前
[BIOS]VSCode zx-6000 编译问题
ide·vscode·编辑器
还是鼠鼠1 小时前
HTTP 请求协议简单介绍
java·开发语言·网络·网络协议·http
浮游本尊1 小时前
Java学习第1天 - 完整版基础语法
java
BigData-01 小时前
vscode vue debug
ide·vue.js·vscode
晨曦5432102 小时前
将 Jupyter Notebook 的默认存储路径从 C 盘迁移到 D 盘,可以通过以下步骤实现:
ide·python·jupyter
on the way 1232 小时前
行为设计模式之Command (命令)
java·开发语言·设计模式
5upport2 小时前
Gradle Version Catalog的IDE辅助工具
gradle·android studio·intellij idea
qqxhb2 小时前
零基础设计模式——行为型模式 - 责任链模式
java·设计模式·责任链模式