i am trying to create a simple workbook using Apache POI and getting the following errors.Using apchhe poi 3.9 kindly help me to get out of this thanks.
Errors:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException
at xlscreate.xlsclass.main(xlsclass.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
CODE:
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.InputStream;
public class xlsclass {
public static void main(String[] args) throws Exception,Throwable{
// Workbook wb = new HSSFWorkbook();
// FileOutputStream fileOut = new FileOutputStream("workbook.xls");
// wb.write(fileOut);
// fileOut.close();
Workbook wb = new XSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream("c:/workbook.xlsx");
wb.write(fileOut);
fileOut.close();
}
}
Apache POI has dependencies. You need to look them up and add them to your classpath. One of those dependency libraries contains this exception class: org.apache.xmlbeans.XmlException. Not sure which one. After that the other answers contain hint’s for the actual bug in your code.