1

In my project I use apache.poi libs to work with excel files. I have dependencies on:

  • apache.poi.ooxml_3.15
  • apache.poi_3.15
  • apache.poi.ooxml_schemas_3.15

jars. So during compilation there are no problems. On runtime:

    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    ...
    Workbook workbook2003 = new HSSFWorkbook(); //1
    Workbook workbook2007 = new XSSFWorkbook(); //2

line 1 works correctly, while line 2 throws exception:

Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook cannot be found by org.apache.poi.ooxml_3.15.0
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 41 more

org.apache.poi.ss.usermodel.Workbook is located in apache.poi_3.15 but during runtime jvm tries to find it in apache.poi.ooxml_3.15. Not sure why?

Maybe someone can help me to fix this problem.

More details about project: - Ide: eclipse neon.1| - it is e4 project - java 8

Ravi Prakash Verma
  • 1,484
  • 1
  • 15
  • 22
Bublik
  • 912
  • 5
  • 15
  • 30

2 Answers2

2

Since XSSFWorkbook works on OOXML schema, it loads the Workbook class from poi.ooxml jar. You might be getting this error because xmlbeams jar is also required as dependency in runtime.

Update

commons-logging, commons-codec, commons-collections, log4j jars are also required for poi. Please check if you have imported them. All of these jars are already there in poi-bin-3.15-20160924 file which you might have downloaded. Please see this page for prerequisites of various components.

Hope this helps!!

Ravi Prakash Verma
  • 1,484
  • 1
  • 15
  • 22
0

The library have probably other runtime depedencies that are needed for second case. Can you try to setup the project as a maven project ? It should solve your problem since maven takes care also for dependencies of your explicitly defined libraries.

gregy4
  • 13
  • 4