I'm using a servlet to upload .xls
(Excel Spreadsheets) files to the server. I'm using the Apache FileUpload API for the upload portion of the business logic, to ensure weather this part is working, I have successfully attempted uploading a .txt file to the Servlet after which — the Apache FileUpload API, from the servlet side gives me an InputStream
from which I print out all the contents of the .txt
on to the console.
The part which isn't working is, when, I attempt to use that InputStream
and forward it to a method in which, I scan the user uploaded .xls
file and print it on the console. The Exception being thrown is:
java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.WorkbookFactory
This happens despite me having added both, poi-3.5-FINAL-20090928.jar
and poi-ooxml-3.5-FINAL-20090928.jar
to the Java Project Build Path. It should be mentioned that the latter file contains the WorkbookFactory
class.
Yet, when I tried scanning a .xls file which was locally present on the hard drive, from which I derived the InputStream
and forward that to print all the cells of the .xls
, it prints out the cells on each row and columns flawlessly on the console. Any solutions?
Best Answer
You're using Apache Commons FileUpload which thus implies that you're using a webapplication. Did you place the libraries in the webapp's
/WEB-INF/lib
folder as you usually should do for any 3rd party libraries? You don't need to do anything with Java Project Build Path. Eclipse will automagically take any libraries in/WEB-INF/lib
in the buildpath and the webapplication, once deployed, will by default take those libraries in the classpath.If that doesn't help, then ensure that you don't have somewhere else an older version of POI in the classpath which may coillide in the classloading. This includes aside from the webapp's
/WEB-INF/lib
under each the appserver's/lib
(and maybe others, depending on make/version/configuration, consult the docs for details) and the JRE's/lib
. If there are older POI versions in there, you need to remove them first. Actually, those folders should not contain any 3rd party webapp-specific libraries, it would only clutter the classpath.