You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调试模式下实例化XSSFWorkbook抛出ClassNotFoundException(org.apache.xerces.util.SecurityManager缺失)问题求助

Troubleshooting ClassNotFoundException for org.apache.xerces.util.SecurityManager When Instantiating XSSFWorkbook

Hey there, let's walk through this weird issue you're facing—especially since it only pops up in debug mode and your old projects worked fine. Here are some targeted fixes to try:

1. First, Fix the Missing Xerces Dependency

Even though your IDE's auto-completion works, your runtime/debug classpath is missing the Xerces library that POI's XSSFWorkbook relies on to parse XML (since .xlsx files are just zipped XML under the hood).

If you're using Maven, add this to your pom.xml:

<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.12.2</version> <!-- Use a version compatible with your POI version; check POI's docs if unsure -->
</dependency>

For Gradle, add this to your build.gradle:

implementation 'xerces:xercesImpl:2.12.2'

Pro tip: If you're using POI's BOM (bill of materials) to manage versions, you can skip the version number here—it'll inherit the correct one from the BOM.

2. Adjust Your Debugger's Exception Breakpoints

You mentioned the exception is hitting a breakpoint, which is why disabling it breaks your debugging flow. Let's tweak that:

  • In IntelliJ: Press Ctrl+Shift+F8 (or go to View → Tool Windows → Breakpoints) to open the breakpoints panel. Look for ClassNotFoundException in the list of exception breakpoints.
  • In Eclipse: Go to Window → Show View → Other → Debug → Breakpoints, then find the ClassNotFoundException entry.

Once you locate it:

  • Either uncheck the breakpoint entirely (if you don't need to catch this specific exception)
  • Or add a condition to exclude the Xerces-related instance: for example, set the condition to !className.equals("org.apache.xerces.util.SecurityManager") so the breakpoint only triggers for other ClassNotFound exceptions.

3. Clean Up Build Caches & Fix Dependency Conflicts

Debug mode sometimes behaves differently if there's cached or conflicting code/dependencies:

  • Run a clean build: For Maven, execute mvn clean install; for Gradle, run ./gradlew clean build.
  • Clear your IDE's cache:
    • IntelliJ: Go to File → Invalidate Caches... → select "Invalidate and Restart"
    • Eclipse: Go to Project → Clean, then select your project and rebuild.
  • Check for dependency conflicts: Use mvn dependency:tree (Maven) or ./gradlew dependencies (Gradle) to see if there are multiple versions of Xerces or conflicting XML parsers (like xml-apis, xalan) in your project. If you find conflicts, exclude the unwanted versions from your dependencies.

4. Force POI to Use JDK's Built-in XML Parser

If adding Xerces doesn't work, you can try making POI use the Xerces implementation that comes bundled with your JDK instead of relying on external dependencies.

Either add these lines before instantiating XSSFWorkbook:

System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");

Or add these VM arguments to your debug configuration:

-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl

Start with steps 1 and 2 first—those are the most likely fixes given your scenario. Since your old project worked, it's almost certainly a missing dependency or a debugger setting that got changed.

内容的提问来源于stack exchange,提问作者Mimmo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 21:02:36