Jasperreports engine JRRuntimeException on report(

2019-07-10 08:12发布

I am creating a java application using DynamicReports and JasperReports.

While trying to show the JasperReportBuilder, I get this error:

...
    DEBUG DefaultExtensionsRegistry - Instantiating extensions registry for system.f
    ont.families using factory class net.sf.dynamicreports.jasper.base.JasperSystemF
    ontExtensionsRegistryFactory
    Exception in thread "AWT-EventQueue-0" Exception in thread "AWT-EventQueue-0"
    Exception: net.sf.jasperreports.engine.JRRuntimeException thrown from the UncaughtExceptionHandler in thread "AWT-EventQueue-0"

I am truly at a lack of ideas here. I am using JDBC-ODBC bridge to get an Access database (the query works). My piece of code (basically creating the report and the columns dynamically) :

JasperReportBuilder report = report();
            try{
                report.setTemplate(Templates.reportTemplate);
                StyleBuilder titleStyle = stl.style(boldCenteredStyle)
                        .setVerticalAlignment(VerticalAlignment.MIDDLE)
                        .setFontSize(15);

                report.title(cmp.horizontalList().add(cmp.image("resources/icon.jpg").setFixedDimension(80, 80)
                    , cmp.text("Gestion de rapports").setStyle(titleStyle)
                    , cmp.text(rapportSelect.getNomListe()).setStyle(titleStyle).setHorizontalAlignment(HorizontalAlignment.RIGHT))
                        .newRow().add(cmp.filler().setStyle(stl.style().setTopBorder(stl.pen2Point())).setFixedHeight(10)));

                Iterator it = rapportSelect.getMappingColonnes().entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry pair = (Map.Entry)it.next();
                    report.columns(col.column((String)pair.getKey(), (String)pair.getValue(), type.stringType()));
                }

                report.pageFooter(Templates.footerComponent);

                String sqlQuery = rapportSelect.getSqlQuery() + " ";

                Statement stmt = GestionDbAdapter.getInstance().get().createStatement();
                ResultSet rs = stmt.executeQuery(sqlQuery);
                report.setDataSource(rs);

                report.show(false);

The whole application is very big, so I only put a piece of my code (which I slightely cleaned for stackoverflow). Please advise me if you want more code.

1条回答
Juvenile、少年°
2楼-- · 2019-07-10 08:37

I'm assuming that you've got a similiar problem just like me. I've got 2 kind of deployments (no web scenario):

  1. Application deployment with all dependent JARs in separate files
  2. Standalone deployment with all JARs packed into one single jar ("jar-with-dependencies")

The second scenario doesn't execute properly and aborts with the same error at the same location as you described.

The reason was that several dependent JasperReport JARs contain a properties file with the same name at the same location on default package level: jasperreports_extension.properties

In the selfcontained JAR scenario they overwrite each other. Finally, there's only one jasperreports_extension.properties and therefore some key-value pairs are missing for a working JasperReport.

Workaround:

Collect all jasperreports_extension.properties files and aggregate their contents into one single jasperreports_extension.properties. Make sure that your deployment gets this special file instead of the original ones. I found duplicate jasperreports_extension.properties files in following dependent artifacts:

  • jasperreports-6.2.2.jar
  • jasperreports-fonts-6.0.0.jar
  • dynamicreports-core-4.1.1.jar
  • dynamicreports-googlecharts-4.1.1.jar
查看更多
登录 后发表回答