views:

1214

answers:

2

I'm working on a project that needs Jasper reporting, I have used the code fragment mentioned below to view the report in NetBeans 6.1 (the report is originally generated and compiled using iReport 3.6.0),my requirement is to print this report using a simple Swing application.

Code fragment:

    public class JasperCheck {

    public static void main(String[] args) {
        String reportSource = "E:/Projects/report.jrxml";
        String reportDest = "E:/Projects/report.html";

        Map<String, Object> params = new HashMap<String, Object>();
        try {

            JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);

            JasperPrint jasperPrint =
                    JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());

            JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest);

            JasperViewer.viewReport(jasperPrint);
        } catch (JRException ex) {
            System.out.println(ex);
        }
    }
}

But when I run this it gives an exception that I couldn't figure out.

Exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:157)
        at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:115)
        at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(JasperCompileManager.java:511)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:215)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:148)
        at src.JasperCheck.main(JasperCheck.java:31)
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.control.CompilationFailedException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 8 more
Java Result: 1

Thanks.

+1  A: 

Try:

JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest);

See JasperExportManager.exportReportToHtmlFile(). I assume that's the method you mean.

cletus
It didn't work, gives the same exception
MMRUser
Yes that's the method
MMRUser
It can't possibly give the same exception. Your exception is because you're passing a HTML filename as the source file and Jasper can't read it. The method I'm suggesting passes **jasperPrint**, which is not an HTML file so it'll either work or throw a different exception.
cletus
I have fixed the code now it gives a different exception
MMRUser
I have figured it out the problem cause because of a missing jar file
MMRUser
A: 

.... I'm having the same problem... sorry... which .jar file was missing to you?? It can probably work for me too!!

help meee... ! :S

Heccer
Really sorry for the late response these are the jar files that need to be added to your class path:groovy-all-1.5.5.jarjasperreports-3.6.0.jarjasperreports-3.5.2.jariText-2.1.0.jarcommons-collections-3.2.1.jarcommons-dbcp-1.2.2.jarcommons-digester-1.7.jarcommons-logging-1.1.jarcommons-beanutils-1.8.0.jarcommons-javaflow-20060411.jarpoi-3.2-FINAL-20081019.jarxercesImpl-2.7.0.jarYou can find these .jar files in jasperreport installation foldersiReport-nb-3.6.0\ireport\modules\ext\iReport-nb-3.6.0\ireport\fonts\tmp\Hope this will help you.
MMRUser