Hot questions for Using JasperReports in grails

Question:

How to create multi language Jasper report using Grails?

I am using Jasper plugin to generate report. I tried using ${R.Resource} but I am unable to track exact path where .property file should be placed.


Answer:

editing the report, in the xml you can specify the resouce boundle containing the .properties. To do that you must put in the attribute resourceBundle of the jasperReport tag the location of your .property file/s. for example, if they are placed under the packege org.mycomp.gui your xml should look like:

 <jasperReport xlsns......   resourceBundle="org/mycomp/gui ......>

in that package you will have for instance gui.properties, gui_en.properties and so on

hope this help

Question:

I want to upgrade my grails server to use Java 8 instead of 7. When I upgrade, I encounter the exception shown below. Other people who have reported similar errors have said that the problem can be fixed by changing the Java version of the IDE, but that doesn't seem to apply here because I get the exception if I run grails from the command line or from Intellij. Other people have reported upgrading tomcat would help, so I'm on the latest from version 7.

My java home is set to Java 8, I've changed the source/target of the compiler to 1.8 to make sure nothing is creeping in. I've cleared all the .class files, refreshed-dependencies, clean-all, rm .slcache, etc and nothing seems to affect this.

BuildConfig.groovy:        compile ":jasper:1.11.0"
BuildConfig.groovy:        build ":tomcat:7.0.70"
BuildConfig.groovy:grails.project.target.level = 1.8
BuildConfig.groovy:grails.project.source.level = 1.8

Note, this plugin is using Jasperreports 5.6.1. I've been unable to determine from TIBCO's website whether their .jars should or should not be able to support Java 8. Also, I'm using grails 2.5.5 and I'm on OSX.

2016-12-05 12:51:56,060 [http-bio-8091-exec-5] ERROR design.JRJdtCompiler  - Compilation error
org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
    at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.<init>(ClassFileReader.java:372)
    at net.sf.jasperreports.engine.design.JRJdtCompiler$1.findType(JRJdtCompiler.java:255)
    at net.sf.jasperreports.engine.design.JRJdtCompiler$1.findType(JRJdtCompiler.java:192)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:113)
    at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromTypeSignature(LookupEnvironment.java:1335)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromVariantTypeSignature(LookupEnvironment.java:1391)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeArgumentsFromSignature(LookupEnvironment.java:1172)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromTypeSignature(LookupEnvironment.java:1340)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createMethod(BinaryTypeBinding.java:550)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createMethods(BinaryTypeBinding.java:630)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.cachePartsFrom(BinaryTypeBinding.java:365)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:688)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:667)
    at org.eclipse.jdt.internal.compiler.Compiler.accept(Compiler.java:296)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:118)
    at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122)
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getType(PackageBinding.java:137)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.findType(Scope.java:1611)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:2708)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2405)
    at org.eclipse.jdt.internal.compiler.ast.SingleTypeReference.getTypeBinding(SingleTypeReference.java:44)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:132)
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:204)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1477)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1175)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:678)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:469)
    at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:756)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:468)
    at net.sf.jasperreports.engine.design.JRJdtCompiler.compileUnits(JRJdtCompiler.java:167)
    at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:201)
    at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:354)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:614)
    at gdbxt.JasperReportJavaService.$tt__compileReport(JasperReportJavaService.groovy:31)
    at gdbxt.ProteinPurificationBatchController$$EQ4X8VQ0.createReport(ProteinPurificationBatchController.groovy:102)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Error 
|
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files
/*
^
1 errors

Error |
    at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:204)
Error |
    at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:354)
Error |
    at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:614)
Error |
    at net.sf.jasperreports.engine.JasperCompileManager$compileReport.call(Unknown Source)
Error |
    at gdbxt.JasperReportJavaService.$tt__compileReport(JasperReportJavaService.groovy:31)

Answer:

Even though I'd seen other people post that a more recent version of Tomcat 7 would work, it looks like updating to Tomcat 8 did the trick for me.

BuildConfig.groovy:        build ":tomcat:8.0.33"

Before trying tomcat 7.0.70 I had been trying tomcat 7.0.55. If tomcat 7.0.70 should have worked and 7.0.55 doesn't, then perhaps the problem was some old 7.0.55 jar was being picked up by 7.0.70.

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?


Answer:

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 :-)