NoClassDefFoundError: org/apache/poi/util/POILogFactory
Asked Answered
U

4

5

I'm trying to use Apache POI Library in Eclipse RCP project. So I added poi, poi-ooxml and poi-ooxml-schemas to project, but still got an Exception java.lang.NoClassDefFoundError: org/apache/poi/util/POILogFactory at org.apache.poi.POIXMLDocumentPart.<clinit>(POIXMLDocumentPart.java:53)

at this line: XWPFDocument doc = new XWPFDocument();

To add poi to project there is a p2-repository and p2-maven plugin with following artifacts:

<artifact>
    <id>org.apache.poi:poi:3.14</id>
    <source>true</source>
    <transitive>false</transitive>                      
    <instructions>
        <Import-Package></Import-Package>
        <Export-Package>*</Export-Package>
        <DynamicImport-Package>*</DynamicImport-Package>
    </instructions>
</artifact>

(and the same with <id>org.apache.poi:poi-ooxml:3.14</id> and <id>org.apache.poi:poi-ooxml-schemas:3.14</id>) .

I tried to use POILoggerFactory directly in code POILogger logger = POILogFactory.getLogger(POIXMLDocumentPart.class); logger.log(POILogger.INFO, "Test"); and it works! I have no idea, what's wrong.

Unscathed answered 16/8, 2016 at 8:26 Comment(0)
K
4

Pls. check the versions of poi.jar and poi-ooxml.jar, if they are the same or any older POI jars are already in your classpath. You can try this piece of code to get the version of POI jar read by your compiler :

ClassLoader classloader =
   org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
URL resPath = classloader.getResource(
         "org/apache/poi/poifs/filesystem/POIFSFileSystem.class");
String path = resPath.getPath();
System.out.println("The actual POI Path is " + path);

Here is the component list for POI - http://poi.apache.org/overview.html#components

To my knowledge, these are the dependencies list for POI

Poi-3.10-Final.jar Poi-ooxml-3.10-Final.jar Poi-ooxml-schemas-3.10.jar Xmlbeans-2.30.jar

I hope it helps.

Kalmick answered 16/8, 2016 at 9:48 Comment(4)
This code returns "The actual POI Path is /org/apache/poi/poifs/filesystem/POIFSFileSystem.class". I don't see any poi-jars in classpath, they are located in Plug-in Dependencies. And there is also no older POI jars. I've seen this list of dependencies, and all of them are in my Plug-in dependencies too. I'm tring to use 3.14 poi versionUnscathed
Is the jar file under root ?Kalmick
Sorry, i don't understand what do you mean. Jar is in Eclipse's pluginsUnscathed
This path indicates : /org/apache/poi/poif‌​s/filesystem/POIFSFil‌​eSystem.class that the jar file may located in root folder of your linux installation.Kalmick
L
3

As suggested by @Niranjan Gattupalli,

The following version of org.apache.poi libraries bind together well.

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>4.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>4.1.1</version>
    </dependency>
Longsome answered 23/3, 2023 at 10:55 Comment(0)
L
0

I ran in to this problem too. It seems to be a problem with packages of the same name across two bundles (I found this article). Once I got this resolved there were more class errors to resolve.

So, after attempting several variations on Import-Package and Require-Bundle, the following is the configuration for the p2-maven plugin which worked for my project:

  <artifacts>
    <artifact>
      <id>org.apache.poi:poi:3.16</id>
      <source>true</source>
      <instructions>
        <Import-Package>*;resolution:=optional</Import-Package>
        <Export-Package>*;-noimport:=true</Export-Package>
      </instructions>
    </artifact>

    <artifact>
      <id>org.apache.poi:poi-ooxml:3.16</id>
      <source>true</source>
      <instructions>
        <Import-Package>*;resolution:=optional</Import-Package>
        <Export-Package>*;-noimport:=true</Export-Package>
        <Require-Bundle>org.apache.poi;bundle-version="[3.16.0,4.0.0)"</Require-Bundle>
      </instructions>
    </artifact>

    <artifact>
      <id>org.apache.poi:poi-ooxml-schemas:3.16</id>
      <source>true</source>
      <instructions>
        <Import-Package>!org.apache.poi,org.apache.xmlbeans.impl.schema;resolution:=optional,*;resolution:=optional</Import-Package>
        <Export-Package>*;-noimport:=true</Export-Package>
        <Require-Bundle>org.apache.poi.ooxml;bundle-version="[3.16.0,4.0.0)"</Require-Bundle>
      </instructions>
    </artifact>
  </artifacts>

The important parts being:

  • ooxml requires the poi bundle (importing org.apache.poi.util does not work)
  • ooxml-schema does not import package org.apach.poi, does import the org.apache.xmlbeans.impl.schema package, and requires the poi-ooxml bundle
Luing answered 8/8, 2017 at 23:59 Comment(0)
R
0

You'd need to include to include package of common bean utils using the below code.

implementation group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.3'

FYI: I was using implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.0.0'

These changes I had to make in build.gradle file in my project.

Reincarnate answered 22/2 at 5:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.