0

So I downloaded Ant POI 5.0.0 and installed (to the best of my knowledge) it to my lib directory for use in my project.

when I try execute the following code:

XSSFWorkbook book = new XSSFWorkbook(new FileInputStream(xlFile));
XSSFSheet sheet = book.getSheetAt(0);

I get "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook" but I know at least this directory and classes are there. What other classes am I missing?

I'm also using the following imports.

import org.apache.poi.hssf.usermodel.HSSFCell; 
import org.apache.poi.ss.usermodel.Cell; 
import org.apache.poi.ss.usermodel.CellStyle; 
import org.apache.poi.ss.usermodel.DataFormat; 
import org.apache.poi.ss.usermodel.Row; 
import org.apache.poi.ss.usermodel.Sheet; 
import org.apache.poi.ss.usermodel.Workbook; 
import org.apache.poi.xssf.usermodel.XSSFRow; 
import org.apache.poi.xssf.usermodel.XSSFSheet; 
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

Just for clarification, I have included my compiler command just in case I am missing something in my classpath as well.

javac -g -d ..\bin SomeApp.java -cp ..\src;..\lib\poi-ooxml-5.0.0.jar;..\lib\poi-5.0.0.jar

new2code
  • 31
  • 5
  • 1
    If you're using external libraries, learn to use Maven or Gradle; it will make your life *much* easier. – chrylis -cautiouslyoptimistic- Nov 02 '21 at 19:43
  • I wish I could. I am stuck in a corporate situation where I only have the basic compiler to work with and no other tools. No version control, no IDE of any sort, etc. Just Notepad and my wits. – new2code Nov 02 '21 at 20:04
  • 2
    mixing hssf and xssf imports seems strange without knowing the details. your classpath misses a few entries. In your restricted situation, I would download the [poi bin](https://poi.apache.org/download.html) archive and [use wildcards](https://stackoverflow.com/questions/219585). An example invocation can be found [on the PPT render page](http://poi.apache.org/components/slideshow/ppt-wmf-emf-renderer.html) in "Instructions to run". – kiwiwings Nov 03 '21 at 00:56
  • Build path now includes all libraries as a wildcard. I also adjusted the import statement to: [import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.DataFormat; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFCell; ] It builds, but same error – new2code Nov 03 '21 at 13:37

1 Answers1

0

Faced a similar issue, using Eclipse Enterprise Enterprise, version: 2019-06 (4.12.0). I had added apache-poi 5 jars in a user library enter image description here

The project compiled fine. But when I run the web application on my location machine, was getting the error

What I was missing in eclipse was to include the following

enter image description here

After this, everything was working fine

Vuzi
  • 185
  • 2
  • 4
  • 13