Hot questions for Using JasperReports in netbeans

Question:

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

Any suggestion would be really helpful. Thank you.


Answer:

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?

Question:


Answer:

Seems like, as @skandigraun has advised, I got some old libraries which missing some class required to run the report.

The Solution is to update these jars :

Apache common collections v2.1 to 3.0.1 Apache Groovy v1.0 to 2.1

and now everything run perfectly.

Question:

My report view doesnt any problem with blanks and it seems in one page. But when I run Netbeans it split two pages. Does anyway for clear blanks?

Note:

*I did:"Remove Line When Blank" but it doesnt solve my problem

My Print Code:

try {
            Connection baglanti = DriverManager.getConnection("jdbc:postgresql://localhost:5432/KontrolCetveli", "postgres", "12qw!'QW");
            String rapor = "C:\Users\00035583\Documents\NetBeansProjects\Kontrol Paneli\src\ayOlusturma.jrxml";
            String temizle = "truncate sorgutablosu";
            st = baglanti.createStatement();
            st.execute(temizle);
            String sql = "insert into sorgutablosu(sicilno,ad,gorev,servisadi,ay) VALUES ('" + txtSicilNo.getText() + "','" + txtAdSoyad.getText() + "',"
                    + "'" + txtGorev.getText() + "','" + ComboServis.getSelectedItem() + "','" + Combom.getSelectedItem() + "') ";
            st = baglanti.createStatement();
            st.execute(sql);
            JasperReport JR = JasperCompileManager.compileReport(rapor);
            JasperPrint JP = JasperFillManager.fillReport(JR, null, baglanti);
            JasperViewer.viewReport(JP);
        } catch (Exception e) {
            e.printStackTrace();
        }


Answer:

I solved issue with selection "float column footer" in report name.

Question:

I'm trying to export the jasper report to .docx file; but I'm getting this error

java.lang.ClassCastException: java.lang.String cannot be cast to net.sf.jasperreports.engine.JasperPrint

I'm using java to develop this.

Here is the code I used

public void generateReport2() throws PrinterException {

try {  
String sourceFileName = "src/POS_bill/esFourReport.jasper";
String printFileName = null;
DataBeanFactory2 DataBean = new DataBeanFactory2();
JRBeanCollectionDataSource beanColDataSource = new      JRBeanCollectionDataSource(DataBean.generateCollection());
Map parameters = new HashMap();
printFileName = JasperFillManager.fillReportToFile(
     sourceFileName,
     parameters,
     beanColDataSource);


JRDocxExporter exp=new JRDocxExporter();   
exp.setParameter(JRExporterParameter.JASPER_PRINT,printFileName);
exp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"src/POS_bill/sample_report2.docx");
exp.exportReport();


} catch (Exception e) {

System.out.println(e);
} 
}

Answer:

Finally I found the answer!

I removed these two lines

exp.setParameter(JRExporterParameter.JASPER_PRINT,printFileName);
exp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"src/POS_bill/sample_report2.docx");

and replaced it with these

exporter.setExporterInput(new SimpleExporterInput(printFileName));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("src/POS_bill/samplereport2.docx"));

and now it works finely!

Question:


Answer:

i Assume you are talking about iReports here. have you tried what is mentioned here (iReport 5.5.1 Doesn't Load)

And yes jasper studio is an eclipse based tool, so it cannot be used outside eclipse