Skip to content

Unable to open XLSX file using Apache POI: NoClassDefFoundError

I’m having problems trying to open an XLSX file with Apache POI.

My code:

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelTest {
    public static void main(String[] args) {
        try(FileInputStream f = new FileInputStream(new File("path/to/my/file.xlsx"))) {
            XSSFWorkbook wb = new XSSFWorkbook(f); // This is the line throwing the exception
        } catch(IOException e) {


Exception thrown:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException
    at my.TEST.ExcelTest.main(
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    ... 1 more


  • Running JDK 7 on MacOS X (Mavericks)
  • Using NetBeans
  • Imported jars (all from Apache POI binary distribution):
    • poi-3.11-20141221.jar
    • poi-ooxml-3.11-20141221.jar
    • poi-ooxml-schemas-3.11-20141221.jar
    • commons-codec-1.9.jar
    • log4j-1.2.17.jar

I can’t even start doing the real stuff, since I can’t even open the book! 🙁

When I saw the exception, I thought “Ok, let’s get xmlbeans and see if it works”, but xmlbeans is moved into Apache’s attic.

Am I missing something? How can I open the workbook?


I think you were right about needing xmlbeans-2.6.0.jar as well. That appears to be one of Poi’s dependencies. I set up a vestigial Maven project with poi, poi-scratchpad, poi-ooxml, and poi-ooxml-schemas as my direct dependencies. Maven yanked in these other JARs as dependencies:

  • commons-codec-1.9.jar
  • xmlbeans-2.6.0.jar
  • stax-api-1.0.1.jar

On further investigation, I see that stax-api is a transitive dependency for xmlbeans.