Search code examples
javaswingjasper-reportsireport

Jasper report working fine in netbeans but gives exception when deployed as jar application


I'm working on my final year project using java swings and jasper reports for reporting.The application including the reports work fine when I run the application in netbeans but when I deploy it to a jar file and then try to execute it using my command prompt I see this huge text of exception.

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
        at java.lang.Class.getConstructor0(Unknown Source)
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(JasperCompileManager.java:472)
        at net.sf.jasperreports.engine.JasperCompileManager.loadEvaluator(JasperCompileManager.java:238)
        at net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(JRFillDataset.java:421)
        at net.sf.jasperreports.engine.fill.JRBaseFiller.(JRBaseFiller.java:428)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:76)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:86)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:56)
        at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:142)
.
.
.
.
....54 more

The following function invokes the jasper report :

    public void printReport(String adID){
       try {
            Map parameters = new HashMap();
            InputStream jasperIS =this.getClass().getResourceAsStream("/Reports/AllHoardings.jasper");
            User connect=new User();
            JasperPrint print=JasperFillManager.fillReport(jasperIS,parameters,connect.getConnection());
            JasperViewer.viewReport(print,false);
        }catch(JRException je){
            System.out.println(je.toString() +" @ line 2043");
        }catch (Exception e) { System.out.println(e.toString());       }
    }

Link to the image :

The Snap Shot


The directory listing in netbeans

Link to the image :

Project directory listing in netbeans


Inside my jar file

Link to the image :

Inside the jar file


Solution

  • java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
    

    This error suggests to me that NetBeans is solving your issues with Groovy and Jasper Reports in a way that your JAR file is not. Check to see if there are JARs missing from your JAR manifest that pertain to Groovy. If yes, add them.