javajasper-reportsapache-poinosuchmethod

JasperReports 5.2 is not working with poi-3.7


I am using JasperReports 5.2 with Apache poi 3.7 in server lib folder. I don't have any other versions of poi in server lib. When I am trying to generate Excel report I am getting below error.

java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFWorkbook.getCreationHelper()Lorg/apache/poi/ss/usermodel/CreationHelper;

I can see this method available in this jar file with help of below link.

http://grepcode.com/file/repo1.maven.org/maven2/org.apache.poi/poi/3.7/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?av=f


Solution

  • This is a sufficiently common problem that the Apache POI FAQ has an entry for it, which even includes code to work out what's wrong

    Basically, somewhere else on your classpath (possibly from your server), there's an older copy of Apache POI. When your code runs, it triggers the loading of the class, and your classloader unhelpfully opts for the older jar, not the newer one.

    If you run the code from the FAQ:

    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);
    

    Then that will tell you where the core of POI is being loaded from. I can virtually guarantee that it won't be the jar you expect... Zap the old POI jars (all of them!), then you should be good to go.

    Well, mostly good to go. Apache POI 3.7 is 3 years old so there have been lots of fixes since then, making it worth looking into upgrading!