2
  • 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.

Alex K
  • 22,315
  • 19
  • 108
  • 236
Madushan Perera
  • 2,568
  • 2
  • 17
  • 36

2 Answers2

4

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?

Alex K
  • 22,315
  • 19
  • 108
  • 236
  • 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. – Madushan Perera Oct 22 '17 at 15:21
  • Looks stange. Did you see this link: [Use lambda expressions inside TextField expression in Jaspersoft Studio 6.3](https://stackoverflow.com/q/41618362/876298)? – Alex K Oct 22 '17 at 15:40
  • I added all required jars to the project build path.. Please correct me If I do wrong. http://ibb.co/gwGagR – Madushan Perera Oct 22 '17 at 16:44
  • 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 Oct 22 '17 at 16:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/157236/discussion-between-alex-k-and-madushan-perera). – Alex K Oct 22 '17 at 17:15
0

update JDK your computer (y) the barbecue-1.5-beta1 jar not compiling of all jdk !

Shinwar ismail
  • 299
  • 2
  • 9