Search code examples
jasper-reportswarbuild.gradlegrails-3.0

Jasper jrxml files not included in Grails 3 war


I am using Jasper Reports in my Grails 3 application to generate PDF files. I had some issue with Jasper Report plugin for Grails. So we are using Jasperreport jars to generate the PDF.

compile 'net.sf.jasperreports:jasperreports:6.2.1'

I created a 'JasperReports' in project level and added all the jrxml and jasper files. In the development environment I use the below way to compile the report.

jasperReport = JasperCompileManager.compileReport('JasperReports/FYF_Report.jrxml')

Everything works fine in development but when the war is generated it is not including the 'JasperReports' folder. I tried adding the folder in conf but it did not work.

Let me know if I am missing any configuration to include the 'JasperReports' folder in war.


Solution

  • I resolved the issue by adding the JasperReports folder in src/main/webapp. Path to access the files will be different in local and Production, So I am getting the real path from context as below

                def sc=session.getServletContext()
                def reportsPath=sc.getRealPath("/")
                jasperReport = JasperCompileManager.compileReport(reportsPath+'JasperReports/FYF_Report.jrxml')