NetBeans: JasperReport exception

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

Code snippet:

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 could not understand.

 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.

+4
source share
3 answers

Try:

 JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest); 

See JasperExportManager.exportReportToHtmlFile() . I assume that you have in mind this method.

0
source

This means that there is no groovy addiction.

We can add groovy-1.7.5.jar (this depends on the version of JasperReports ) in the classpath to solve this problem.

We can find the groovy dependency in the JasperReports library pom.xml . For JR 4.5.0, this is:

 <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>1.7.5</version> <scope>compile</scope> <optional>true</optional> </dependency> 

In the case of using maven we can add this dependency to the project:

 <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>1.7.5</version> </dependency> 
+9
source

This is due to the fact that when you created the report, you selected the language as Grrovy, but this is using jrxml in a java program. In jrxml file

+3
source

Source: https://habr.com/ru/post/921923/


All Articles