4

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

Alex K
  • 21,162
  • 18
  • 101
  • 217
Venu
  • 183
  • 4
  • 19
  • May be you have several versions of *poi* library in classpath. May be your server application contains another version of this lib – Alex K Oct 16 '13 at 06:19
  • The *JasperReports API 5.2* is using *org.apache.poi 3.7* – Alex K Oct 16 '13 at 06:20
  • @AlexK, I had old poi jar contents with different jar name in server lib. I removed it and I am not getting any errors now. – Venu Oct 16 '13 at 13:20

3 Answers3

4

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!

Gagravarr
  • 43,370
  • 9
  • 94
  • 140
  • There is a jar file in my server with different name but old poi jar contents. I didn't realize this until I ran above four lines of code. I removed that jar file and jasper 5.2 is working with poi 3.7. Thank you ! – Venu Oct 16 '13 at 13:17
2

You can see the appropriate apache poi version by inspecting your relevant maven repo for Jasper.

I happen to be on Jasper 6.1:

http://repo2.maven.org/maven2/net/sf/jasperreports/jasperreports/6.1.0/jasperreports-6.1.0.pom

which points to apache poi 3.10.1.

Without the versions matching, you're likely to experience all sorts of wierdnesses. Yes I made up that word.

Blamkin86
  • 877
  • 7
  • 8
0

I am using iReport 5.5.0 with the jar below ...

poi-3.13.jar
jasperreports-5.0.4.jar
jackson-all-1.9.0.jar

and it works fine...

Mr. Mak
  • 735
  • 9
  • 21