JasperReports not work on Grails 2.4: Could not initialize class net.sf.jasperreports.engine.xml.JRXmlDigesterFactory

StackOverflow https://stackoverflow.com//questions/25077694

Question

I'm using grails version 2.4.0 and JasperReports plugin: 1.9.0 (also tried version jasper-1.10.0-SNAPSHOT) but when I export to pdf I got errors.

When I first start project, I run export report and got this message

org.apache.commons.collections.map.ReferenceMap

After that when I try again and it shows this error.

Could not initialize class net.sf.jasperreports.engine.xml.JRXmlDigesterFactory

It seems to be in competitive with version 2.4.0 because it works on 2.2.4

Here my code

In controller

def results = new ArrayList()
        def reportFolder = "${grailsApplication.parentContext.getResource('reports').file.absolutePath}"
        def sep = System.getProperty('file.separator')
        def app = Applicant.get(2)
        results.add(
                first: app.firstName,
                middle: app?.middleInitial,
                last: app.lastName,
                ssn: app.ssn,
                workPhone: app.workPhone,
                homePhone: app.homePhone
        )
reportService.exportPDFReport("${reportFolder}${sep}aaa.jrxml", results, params, response)

In service (note that service named: reportService)

def exportPDFReport(String reportPath, results, params, response) {
        def temp_file = File.createTempFile("jasperReport", ".pdf")
        def jrDataSource = new JRMapCollectionDataSource(results)
        JasperReport jReport = JasperCompileManager.compileReport(reportPath)
        JasperPrint print = JasperFillManager.fillReport(jReport, params, jrDataSource)
        JasperExportManager.exportReportToPdfFile(print, temp_file.absolutePath)
        response.setContentType("application/force-download")
        response.setHeader("Content-Transfer-Encoding", "binary")
        response.setHeader("Content-disposition", "attachment; filename=${jReport.name}.pdf")
        response.outputStream << temp_file.newInputStream()
        temp_file.deleteOnExit()
    }

Any ideas?

Was it helpful?

Solution

In version 2.4 or later. you can't combine jasper plugin because it is missing libraries from third part.

It is very easy to resolve that problem. You only need copy these jars to your /lid

  • org.apache.commons.collections.jar
  • commons-beanutils-1.9.2.jar

Sure 100% it work :-)

OTHER TIPS

In version 2.4 the Holder static classes where removed. For plugins that still use these classes they cause errors. I would also try version 2.4.2 instead for grins. Could you also edit and give us a complete stack trace to help in debugging.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top