Jump to content
We've recently updated our Privacy Statement, available here ×

XLS file output error


tvent

Recommended Posts

I've been unable to get Jasper Reports 4.5.1 to output to an XLS file although the output to HTML, PDF and CSV work fine. The runtime error occurs after the report object has been populated and the results are about to be exported to the XLS file. The error looks as follows:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Sheet
        at com.gtwm.jasperexecute.RunJasperReports.generateXlsReport(RunJasperReports.java:192)
        at com.gtwm.jasperexecute.RunJasperReports.main(RunJasperReports.java:485)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Sheet
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 2 more

Line 192 of the launching code looks like:

        JRXlsExporter exporter = new JRXlsExporter();

The code block around this line is:

        parameters.put(net.sf.jasperreports.engine.JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
        JasperPrint print = generateReport(reportDefinitionFile, dbType, databaseName,
                        databaseUsername, databasePassword, databaseHost, parameters);
        JRXlsExporter exporter = new JRXlsExporter();
        List jasperPrintList = new ArrayList();
        jasperPrintList.add(print);
        exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList);
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outputFileName);
        exporter.exportReport();

I've located the jar containing the 'org/apache/poi/ss/usermodel/Sheet' class (poi-3.7-20101029.jar) and placed a copy in the 'lib' directory of the directory from which the main jar is being launched. I've tried forcing the classpath to include the 'lib' directory using 'java -cp lib' before the rest of the options but that didn't help. I'm assuming that 'lib' must already be in the classpath as the 'jasperreports-4.5.1.jar' is being found without a problem. For test purposes I've placed println() statements before and after the line beginning 'JRXlsExporter exporter =' and can see the first but not the second line displayed indicating that the failure occurred when trying to instantiate the JRXlsExporter class.

Any guidance to overcome this issue would be appreciated.

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

JasperReports 4.5.1 depends on Apache POI 3.7 in order to generate Excel documents. If an older POI version is set in your app's classpath, it's possible to get some NoClassDefFoundErrors like this one.

Please check the classpath and see if it contains the appropriate POI version. If possible, try to upgrade to 3.7.

Hope this helps,

sanda

Link to comment
Share on other sites

Thanks for your suggestion, but I had previously copied the 'poi-3.7-20101029.jar' library from the jasperreports-4.5.1 package into the ‘lib’ containing all the other libraries.  So this does not appear to be the cause.

Any other suggestions?

 

Link to comment
Share on other sites

Hi there,

Apparently I missed the 'I've located the jar containing ...' paragraph in your previous post, sorry.

Now, after reading it, it's obvious that POI 3.7 jar is present in the lib directory. In this case, try to ensure that it's the only POI jar in the lib directory, or in the classpath. Older jars, if present, should be completely removed.

In the case you are running your classes directly from a command line, try to specify exactly the jar names when calling the 'java -cp lib' command.

Hope this helps. I have no other clues here.

sanda

 



Post Edited by shertage at 03/20/2012 10:24
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...