javagrailsgroovyjasper-reportsjasper-plugin

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


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?


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

    Sure 100% it work :-)