H4SN
H4SN

Reputation: 1748

Error in creating a simple workbook using Apache POI

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();


     }
}

Upvotes: 0

Views: 6233

Answers (2)

Gagravarr
Gagravarr

Reputation: 48366

Apache POI has a number of dependencies. The full list of the dependencies for each part of Apache POI are given on the website

If you use Maven as your build tool, it'll automatically suck down the dependencies when you define your code as depending on Apache POI (that's all defined). If you use Eclipse or Ant, then you should download the Binary (-bin-) package of Apache POI, and you'll then find all the dependencies in there ready to go.

(For your specific error, you're missing xmlbeans jar, but I suspect you could also be missing some other things to and that's the first one hit)

Upvotes: 1

John Smith
John Smith

Reputation: 2330

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.

Upvotes: 1

Related Questions