How to avoid java.lang.NoSuchMethodError: org.apache.poi.util.IOUtils.copy(Ljava/io/InputStream;Ljava/io/OutputStream;) in Apache POI

只谈情不闲聊 提交于 2019-11-28 00:47:41

I got this error today: "java.lang.NoSuchMethodError:org.apache.poi.util.POILogger.log(I[Ljava/lang/Object;)V]"

It looks different from your error, but quite similar. FYI, I'm using maven to manage jars. After some experiment, I found out the root case is the poi.jar and poi-ooxml.jar's version are not consistent.

This configuration will get an error:

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.12</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.13</version>
    </dependency>

I changed the version of poi.jar from 3.12 to 3.13

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.13</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.13</version>
    </dependency>

bingo, problem solved. I hope this will help someone who ran into this kind of Exception.

See the Apache POI FAQ entry on this very topic. What has almost certainly happened is that you have added a new copy of POI to your classpath, but an older version was already there (from an earlier need, your framework etc), and Java is now getting confused about which one to use.

Firstly, you'll want to use a snippet of code like this to work out where POI is coming from:

ClassLoader classloader =
   org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
URL res = classloader.getResource(
         "org/apache/poi/poifs/filesystem/POIFSFileSystem.class");
String path = res.getPath();
System.out.println("Core POI came from " + path);

Use that to identify the older jar(s) and remove them.

Then, use the POI Components Page to work out what Jars you need to use, and what their dependencies are. Finally, add the latest jars to your classpath, and you'll be good to go!

You almost certainly have an older version of POI on your classpath.

See The Apache POI FAQ

Go here: http://poi.apache.org/download.html

download the tar.gz -> extract it and add to the build classPath all the jars from it.

align the pom versions of 'poi' and 'poi-ooxml' it will do the work

<dependencies>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.17</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.17</version>
    </dependency>
</dependencies>
venkyreddy

I got same problems like you,the solution is you need to import all jar files to run your program.These are mandatory for running your project

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

From the very beginning, poi-ooxml and poi version must be identical.

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.16</version> <---------------this.
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.16</version> <---------------this.
</dependency>

I had a similar issue with apache Tika (java.lang.NoSuchMethodError Error): javax.servlet.ServletException: java.lang.NoSuchMethodError: org.apache.poi.util.IOUtils.closeQuietly(Ljava/io/Closeable;)

I resolved the issue by updating the POI jars.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!