Jasperreports engine JRRuntimeException on report().show

我是研究僧i 提交于 2019-12-24 00:27:03

问题


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:


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


来源:https://stackoverflow.com/questions/37440172/jasperreports-engine-jrruntimeexception-on-report-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!