net.sf.jasperreports.engine.JRException Error when running jar file, but run fine in IDE

Hi.

I just wrote a program in Eclipse (2022-03) as simple Java project (not even maven) that read excel on my computer into java (using Apache POI library) and write it to jasper report.
It run in Eclipse and report is generated perfectly fine. But when I export as runnable JAR, it's got errors eventhough I include all the needed libraries in the JAR, include jasperreports-6.19.1.jar and poi-5.2.2.jar set.
I'm using jdk 12.0.2.

run by command: java -jar .\jarname.jar

This is the error

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
D:\eclipse-workspace\Rent\Condo_1651557749766_654059.java:18: error: cannot find symbol
public class Condo_1651557749766_654059 extends JREvaluator
                                                ^
  symbol: class JREvaluator
D:\eclipse-workspace\Rent\Condo_1651557749766_654059.java:25: error: cannot find symbol
    private JRFillParameter parameter_MONTH = null;
            ^
  symbol:   class JRFillParameter
  location: class Condo_1651557749766_654059
D:\eclipse-workspace\Rent\Condo_1651557749766_654059.java:26: error: cannot find symbol
    private JRFillParameter parameter_YEAR = null;
            ^
  symbol:   class JRFillParameter
  location: class Condo_1651557749766_654059
D:\eclipse-workspace\Rent\Condo_1651557749766_654059.java:27: error: cannot find symbol
    private JRFillField field_roomType = null;
            ^
  symbol:   class JRFillField
  location: class Condo_1651557749766_654059
D:\eclipse-workspace\Rent\Condo_1651557749766_654059.java:4: error: package net.sf.jasperreports.engine does not exist
import net.sf.jasperreports.engine.*;
^
D:\eclipse-workspace\Rent\Condo_1651557749766_654059.java:5: error: package net.sf.jasperreports.engine.fill does not exist
import net.sf.jasperreports.engine.fill.*;
^
D:\eclipse-workspace\Rent\Condo_1651557749766_654059.java:50: error: cannot find symbol
        parameter_MONTH = (JRFillParameter)pm.get("MONTH");
                           ^
  symbol:   class JRFillParameter
  location: class Condo_1651557749766_654059
D:\eclipse-workspace\Rent\Condo_1651557749766_654059.java:51: error: cannot find symbol
        parameter_YEAR = (JRFillParameter)pm.get("YEAR");
                          ^
  symbol:   class JRFillParameter
  location: class Condo_1651557749766_654059
D:\eclipse-workspace\Rent\Condo_1651557749766_654059.java:60: error: cannot find symbol
        field_roomType = (JRFillField)fm.get("roomType");
                          ^
  symbol:   class JRFillField
  location: class Condo_1651557749766_654059
9 errors
.
        at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:229)
        at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:358)
        at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:344)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:609)
        at GenerateJasper.generateReport(GenerateJasper.java:40)
        at ExcelRead.main(ExcelRead.java:86)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)

 

And this is part of my code that generate jasper report
 

try {
            JRDataSource jrDataSource = new JRBeanCollectionDataSource(dataList);
 
 
            HashMap<String, Object> dataParam = new HashMap<>();
            dataParam.put("MONTH", date.substring(0, 2));
            dataParam.put("YEAR", date.substring(2, 6));
 
            InputStream input = new BufferedInputStream(new FileInputStream("/eclipse-workspace/Rent/jasper/Condo.jrxml"));
            JasperReport jasperReport = JasperCompileManager.compileReport(input);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, dataParam, jrDataSource);
            OutputStream output = new FileOutputStream(new File(outputPath+"/"+outputName));
            JasperExportManager.exportReportToPdfStream(jasperPrint, output);
        } catch (Exception e) {
            e.printStackTrace();
        }

Could anyone help me?

bigrun_sarun's picture
Joined: May 1 2022 - 5:30am
Last seen: 1 month 3 weeks ago

    

dprogrammer - 1 month 3 weeks ago

2 Answers:

Seems like I miss the ECJ dependency jar. That jar will make executable jar from eclipse can run on command shell. The program itself doesn't need that jar, but the executable jar does.

bigrun_sarun's picture
Joined: May 1 2022 - 5:30am
Last seen: 1 month 3 weeks ago

Your jar might be missing dependency jars. You should create a fat jar so that it contains all required dependent jars. .Can you also add sysouts to see what date values are being passed to report params? 

dprogrammer's picture
Joined: Jul 19 2006 - 7:37am
Last seen: 1 month 1 week ago
Feedback