0

I'm new to Java and am trying to learn how to read/write to excel using the Apache POI. As of now, I am just trying to write a new excel file, but even after throwing the IO exception, I am getting a java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException exception.

Here is my code:

package ExcelDemo;

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

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo {

    public static void main (String[]args) throws IOException {
        try {
            XSSFWorkbook workbook = new XSSFWorkbook();
            FileOutputStream out = new FileOutputStream(new File("C:/Users/colin/IdeaProjects/FinancialIndependence/src/ExcelDemo.xlsx"));
            workbook.write(out);
            out.close();
        }
        catch(Exception e){
            System.out.println(e);
        }

        System.out.println("Excel file outputted");
    }
}

Here is the error I am getting:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException at ExcelDemo.Demo.main(Demo.java:13) Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) ... 1 more

Process finished with exit code 1

PotatoMan
  • 71
  • 6
  • The problem is most likely not with your code but with the classpath you provide to the JVM when you start it. – JJF Aug 10 '18 at 18:33
  • 3
    Do you have xmlbeans-2.6.0.jar in your classpath? It is included with the POI 3.17 distribution download. – rgettman Aug 10 '18 at 18:35
  • I think I do. You're talking about this right @rgettman and @JJF? https://imgur.com/a/Yw27w64 – PotatoMan Aug 10 '18 at 18:46

1 Answers1

0

My idiot self didn't include the commons-collections4-4.1.jar file into the class path... Thanks for all the advice + help!

PotatoMan
  • 71
  • 6