TIBCOSoftware / jasperreports

JasperReports® - Free Java Reporting Library
https://community.jaspersoft.com/downloads/community-edition/
GNU Lesser General Public License v3.0
1.06k stars 403 forks source link

Issue with loading .jasper files in JasperReports 7.0.0 #455

Closed pvncoder closed 4 months ago

pvncoder commented 4 months ago

I recently migrated my Spring Boot application from JasperReports version 6.21.3 to 7.0.0. The following code snippet, responsible for loading my compiled jasper file (.jasper) and generating a JasperPrint, worked fine in the previous version but now throws an error in the new version:

try (InputStream stream = getClass().getClassLoader().getResourceAsStream(jasperReportType.getPath())) {
    return JasperFillManager.fillReport(stream, parameters, connection);
}

In JasperReports 7.0.0, I am encountering the following error:

net.sf.jasperreports.engine.JRRuntimeException: Unable to load template
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.loadTemplate(JRXmlTemplateLoader.java:225) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.load(JRXmlTemplateLoader.java:257) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.loadTemplate(JRXmlTemplateLoader.java:115) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.fill.JRFillReportTemplate.loadTemplate(JRFillReportTemplate.java:125) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.fill.JRFillReportTemplate.evaluate(JRFillReportTemplate.java:93) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.fill.JRBaseFiller.collectTemplates(JRBaseFiller.java:793) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.fill.JRBaseFiller.collectTemplateStyles(JRBaseFiller.java:819) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.fill.JRBaseFiller.collectStyles(JRBaseFiller.java:764) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.fill.JRBaseFiller.loadStyles(JRBaseFiller.java:711) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:592) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:416) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:121) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:104) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:529) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:490) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:928) ~[jasperreports-7.0.0.jar:7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa]
    at br.com.sysagro.service.JasperServiceImpl.generateReport(JasperServiceImpl.java:53) ~[classes/:?]

It seems that JasperReports 7.0.0 is unable to locate the .jasper file in the resources directory. This issue did not occur in version 6.21.3. I have verified that the path to the .jasper file is correct and that the file exists in the resources directory. Here is a screenshot of the code causing the issue: image Please let me know if you need any further information or if there are any potential workarounds.

teodord commented 4 months ago

The exception is not about report files, but rather about style template files (.jrtx). Please note that in version 7, both .jrxml and .jrtx files have changed their syntax and you need to use Jaspersoft Studio 7 to convert them to the new syntax. Compiled report files (.jasper) need to be recompiled using version 7 of the library.

I hope this helps. Teodor

gbouget commented 4 months ago

It seems that JasperReports 7.0.0 is unable to locate the .jasper file in the resources directory. This issue did not occur in version

I agree with teodord : unable to load template because there is a parsing problem due to syntax incompatibility since v7. You can detect the problematic file by adding a breakpoint to JRXmlTemplateLoader.loadTemplate(), line 115 and reading the parameter named location.

pvncoder commented 4 months ago

Thank you guys. The issue was with my .jrtx file. I opened it in Jasper Studio 7.0, made a fake change, and saved it to get the new syntax. It worked perfectly.