java NetBeans:JasperReport 异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1576532/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NetBeans:JasperReport Exception
提问by Switch
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.
我正在做一个需要 Jasper 报告的项目,我使用下面提到的代码片段在 NetBeans 6.1 中查看报告(报告最初是使用 iReport 3.6.0 生成和编译的),我的要求是使用一个简单的 Swing 应用程序。
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.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.
谢谢。
采纳答案by cletus
Try:
尝试:
JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest);
See JasperExportManager.exportReportToHtmlFile(). I assume that's the method you mean.
见JasperExportManager.exportReportToHtmlFile()。我假设这就是你的意思。
回答by Alex K
It means that the groovylibrary dependency is missing.
这意味着groovy缺少库依赖项。
We can add the groovy-1.7.5.jar(it depends on JasperReportsversion) in classpath to resolve this issue.
我们可以在类路径中添加groovy-1.7.5.jar(取决于JasperReports版本)来解决这个问题。
We can find the groovy's dependency in the the JasperReportslibrary pom.xmlfile. For the JR 4.5.0 version it is:
我们可以groovy在JasperReports库pom.xml文件中找到的依赖项。对于 JR 4.5.0 版本,它是:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.5</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
In case of using mavenwe can add this dependency to the project:
在使用的情况下,maven我们可以将此依赖项添加到项目中:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.5</version>
</dependency>
回答by user760658
This is because, while creating a report you have selected language as Grrovy but this using jrxml in java program.In jrxml file,
这是因为,在创建报告时,您已将语言选择为 Grrovy,但这在 java 程序中使用 jrxml。在 jrxml 文件中,

