سؤال

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

هل كانت مفيدة؟

المحلول

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!

نصائح أخرى

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.

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...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top