Jasper Report syntax error on compiling

12,157

I tried to replace the jtd compiler that used by iReport with new version of jtd compiler (used by JasperReports 6.3).

The last version of iReport is 5.6.0 and it is using JasperReports 5.6.0 behind the scene.

The JasperReports 5.6 is using the jdt 3.1, you can find this dependency at pom.xml:

<dependency>
    <groupId>eclipse</groupId>
    <artifactId>jdtcore</artifactId>
    <version>3.1.0</version>
    <scope>compile</scope>
</dependency>

It means that JasperReports API is using the old version jdt that has not support for Java 8.

For example, the net.sf.jasperreports.engine.design.JRJdtCompiler class is using the jdt core. It means that changes of jdt API can break the compiling mechanism.

Despite these facts I continued my experiment and replace the jdt with new version: 4.3.1 (this version is used by JasperReports 6.3). This version allow us to use Java 8 syntax at templates.

I also set properties at iReport:

org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.source=1.8

But I got the error (as expected) during compiling the template (jrxml) via iReport:

java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getErrors()[Lorg/eclipse/jdt/core/compiler/IProblem;     
at com.jaspersoft.ireport.designer.compiler.ExtendedJRJdtCompiler$CompilerRequestor.acceptResult(ExtendedJRJdtCompiler.java:96)     
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:480)     
at net.sf.jasperreports.engine.design.JRJdtCompiler.compileUnits(JRJdtCompiler.java:167)     
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:201)     
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:512)   

It means that my attempt failed, because the jdt API was changed in new version. But JasperReports API is still using "old" methods instead of methods from new jdt.jar.

Solutions as I see:

  1. To stop using unsupported IDE and replace it with Jaspersoft Studio
  2. Don't use compiling at IDE (iReport) and try to compile/test reports with Java code.

More information:

Use lambda expressions inside TextField expression in Jaspersoft Studio 6.3

How to use lambda expression in jrxml file?

Share:
12,157
Madushan Perera
Author by

Madushan Perera

Updated on June 04, 2022

Comments

  • Madushan Perera
    Madushan Perera almost 2 years
    • Jasper report - Netbeans latest plugin for ireport (plugin for 7.4)
    • JDK - 1.8
    • Netbeans 8.2

    I am using java 8 streams inside the jrxml file. Stream function working fine outside the jrxml and when I compile the report It gives me below error :

    Compilation exceptions: com.jaspersoft.ireport.designer.compiler.ErrorsCollector@3155ed77
    
    net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
    1. Syntax error on token "-", -- expected
    .sorted(java.util.Comparator.comparing(p -> p.getId())) //$JR_EXPR_ID=9$
                                             ^
    2. Syntax error on token "-", -- expected
    .filter(p -> !p.isIsComplete()).filter(p -> p.isStatus()) //$JR_EXPR_ID=9$
              ^
    3. Syntax error on token "-", -- expected
    .filter(p -> !p.isIsComplete()).filter(p -> p.isStatus()) //$JR_EXPR_ID=9$
                                             ^
    4. Syntax error on token "-", -- expected
    .filter(com.court.handler.FxUtilsHandler.distinctByKey(p -> p.getMemberLoanCode())) //$JR_EXPR_ID=9$
                                                             ^
    5. Syntax error on token "-", -- expected
    .sorted(java.util.Comparator.comparing(p -> p.getId())) //$JR_EXPR_ID=9$
                                             ^
    6. Syntax error on token "-", -- expected
    .filter(p -> !p.isIsComplete()).filter(p -> p.isStatus()) //$JR_EXPR_ID=9$
              ^
    7. Syntax error on token "-", -- expected
    .filter(p -> !p.isIsComplete()).filter(p -> p.isStatus()) //$JR_EXPR_ID=9$
                                             ^
    8. Syntax error on token "-", -- expected
    .filter(com.court.handler.FxUtilsHandler.distinctByKey(p -> p.getMemberLoanCode())) //$JR_EXPR_ID=9$
                                                             ^
    9. Syntax error on token "-", -- expected
    .sorted(java.util.Comparator.comparing(p -> p.getId())) //$JR_EXPR_ID=9$
                                             ^
    10. Syntax error on token "-", -- expected
    .filter(p -> !p.isIsComplete()).filter(p -> p.isStatus()) //$JR_EXPR_ID=9$
              ^
    11. Syntax error on token "-", -- expected
    .filter(p -> !p.isIsComplete()).filter(p -> p.isStatus()) //$JR_EXPR_ID=9$
                                             ^
    12. Syntax error on token "-", -- expected
    .filter(com.court.handler.FxUtilsHandler.distinctByKey(p -> p.getMemberLoanCode())) //$JR_EXPR_ID=9$
                                                             ^
    12 errors
    
        at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:204)
        at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:512)
        at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1443)
        at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:68)
        at org.openide.util.lookup.Lookups.executeWith(Lookups.java:303)
        at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2058)
    

    Here is my variable expression :

    <variableExpression><![CDATA[$F{memberLoans}.stream()
    .sorted(java.util.Comparator.comparing(p -> p.getId()))
    .filter(p -> !p.isIsComplete()).filter(p -> p.isStatus())
    .filter(com.court.handler.FxUtilsHandler.distinctByKey(p -> p.getMemberLoanCode()))
    .collect(java.util.stream.Collectors.toList())]]></variableExpression>
    

    I already add my application jar and latest jdt-compiler jar to the classpath and changed the source to 1.8 as well but still It gives me the above mentioned error.

    Image_1

    Image_2

    Any suggestion would be really helpful. Thank you.

  • Madushan Perera
    Madushan Perera over 6 years
    Thanks for the answer and I tried with TIBCO Jaspersoft also.. but again the report is not compiling. If you need I can ask another question.
  • Alex K
    Alex K over 6 years
  • Madushan Perera
    Madushan Perera over 6 years
    I added all required jars to the project build path.. Please correct me If I do wrong. ibb.co/gwGagR
  • Alex K
    Alex K over 6 years
    Did you set org.eclipse.jdt.core.compiler.*=1.8 properties? I did not add jdt at libraries with my JSS 6.3.1
  • Alex K
    Alex K over 6 years