javajasper-reports

Jasperreports in Java: Unable to load report


I've a java-swing app where one of the features is generating pdf representation of the java objects. I recently changed the project jdk to 24 and jasper to 7.0.3. Since then, when I try to fill a report when the app is running from IntelliJ everything is OK, but when I run the jar or package it, I get:

net.sf.jasperreports.engine.JRException: Unable to load report
        at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:173)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:150)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:121)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:108)
        at SabaJasperPrinter.printDoc(SabaJasperPrinter.java:86)
        at PrintoutDialog.lambda$print$0(PrintoutDialog.java:268)
        at java.base/java.lang.Thread.run(Thread.java:1447)

I've tried every solution and troubleshooting method I know and have found on the net. Nothing helps. I've checked the dependencies. I've tried to use the jasper files instead of jrxml, avoiding the need to use: "JasperDesign jasperDesign = JRXmlLoader.load(input);" I've updated the Jaspersoft Studio version to 7.0.3 and converted the jrxml files to 7.0.3. Nothing works!

File input = new File(Saba.RESOURCE_PATH + jrxmlPath+".jrxml");
        JasperDesign jasperDesign = JRXmlLoader.load(input);
        JRPropertiesUtil.getInstance(DefaultJasperReportsContext.getInstance())
                .setProperty("net.sf.jasperreports.default.font.name", "Calibri");
        JRPropertiesUtil.getInstance(DefaultJasperReportsContext.getInstance())
                .setProperty("net.sf.jasperreports.default.pdf.font.name", "Calibri");

        JasperReport report = JasperCompileManager.compileReport(jasperDesign);
        JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource);
        //JasperViewer.viewReport(jasperPrint);

        if (jasperPrint != null) {
            if(printout.isCreateAndOpen()){
                f = File.createTempFile(filePrefix+"_", "."+printout.getDefaultFileTypeOnlyExtension());
                switch (printout.getDefaultFileTypeOnlyExtension()){
                    case "pdf" -> JasperExportManager.exportReportToPdfFile(jasperPrint, f.getAbsolutePath());
                    case "html" -> JasperExportManager.exportReportToHtmlFile(jasperPrint, f.getAbsolutePath());
                    case "xlsx" -> {
                        File xlsxFile = new File(f.getAbsolutePath());
                        JRXlsxExporter exporter = new JRXlsxExporter();
                        exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
                        exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(xlsxFile));
                        SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
                        configuration.setOnePagePerSheet(false);
                        configuration.setDetectCellType(true);
                        configuration.setWhitePageBackground(true);
                        exporter.setConfiguration(configuration);
                        exporter.exportReport();
                    }
                    case "docx" -> {
                        File docxFile = new File(f.getAbsolutePath());
                        JRDocxExporter exporter = new JRDocxExporter();
                        exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
                        exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(docxFile));
                        SimpleDocxReportConfiguration configuration = new SimpleDocxReportConfiguration();
                        configuration.setFlexibleRowHeight(true);
                        exporter.setConfiguration(configuration);
                        exporter.exportReport();
                    }
                    default -> JasperExportManager.exportReportToPdfFile(jasperPrint, f.getAbsolutePath());
                }
                Desktop.getDesktop().open(f);
                readyFilePath = f.getAbsolutePath();
            }else{
                readyFilePath = print(jasperPrint, false);
            }
        }

Solution

  • I had the same problem, the solution was merging the jasperreports_extension.properties file in the fat jar which was not done in my Gradle build. Check the file content in your jar and compare with the files in your runtime classpath.