7

我刚刚尝试了 Jasper Report,我正在关注这个网站的教程

我还下载了示例源然后运行它并且没有错误。但是当我使用创建自己的报告时iReport,对其进行编译,然后将.jasper文件添加到我的项目中。当exception我运行我的程序时:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/callsite/CallSiteArray
    at report2_1343895135169_749208.$createCallSiteArray(calculator_report2_1343895135169_749208)
    at report2_1343895135169_749208.$getCallSiteArray(calculator_report2_1343895135169_749208)
    at report2_1343895135169_749208.<init>(calculator_report2_1343895135169_749208)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(JRAbstractJavaCompiler.java:112)
    at net.sf.jasperreports.engine.design.JRAbstractCompiler.loadEvaluator(JRAbstractCompiler.java:333)
    at net.sf.jasperreports.engine.JasperCompileManager.getEvaluator(JasperCompileManager.java:265)
    at net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(JRFillDataset.java:457)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:379)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61)
    at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:153)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:82)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:634)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:956)
    at View.MainGUI.btnExportActionPerformed(MainGUI.java:871)
    at View.MainGUI.access$800(MainGUI.java:50)
    at View.MainGUI$10.actionPerformed(MainGUI.java:541)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6267)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6032)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.callsite.CallSiteArray
    at java.lang.ClassLoader.findClass(ClassLoader.java:359)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 50 more

这是我用于显示报告的按钮操作(这只是示例,报告仅包含一个带有参数的文本:outputText):

Map params = new HashMap();
params.put("outputText", "Hello world");
try {
        JasperPrint printer = JasperFillManager.fillReport(getClass().getResourceAsStream("report2.jasper"), params, new JREmptyDataSource());
        JasperViewer jv = new JasperViewer(printer);
        jv.show();
    } catch (JRException ex) {
        ex.printStackTrace();
    }

如果有dependency问题,我已经将所有需要的 jar 导入到我的项目中,当我使用.jasper该教程中的文件时没有问题,是因为版本不同iReport吗?

4

6 回答 6

18

或者,您可以更改 .jrxml 文件,查找

language="groovy"

并将其更改为

language="java"
于 2013-11-23T13:39:00.360 回答
8

可能是因为版本不匹配。如果您想知道您需要哪个版本的 Groovy,您可以查看 Jasper 的 Maven 存储库:

http://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports/4.6.0

从这里您可以看到Jasper 4.6.0需要Groovy 1.7.5

于 2012-08-02T08:43:25.070 回答
4

您需要使用 CallSiteArray 类的附加 Jar 包。

http://groovy.codehaus.org/下载

于 2012-08-02T08:33:39.387 回答
0

我在使用 Jasper iReport Tool 5.6.0 时遇到了同样的问题,我的语言是 Java,我将正确的 jasper 报告库降级为 iReport Tool 5.1.0,它的工作原理就像一个魅力......希望状态仍然如此......

于 2015-02-02T09:56:21.793 回答
0

无需更改库,如果是 Ireport 5.X 版本,您可以在主报告属性的语言部分更改它,只需从 groovy 更改为 java 并且报告不会给出任何错误。

于 2015-07-03T08:15:57.247 回答
0

简单的答案

脚步:

1从报告检查器( Windows->报告检查器)中选择您的根文件夹,即 report1.jsxml 2转到属性选项卡并单击语言选项卡,然后选择 JAVA

开始编译和预览您的应用程序...

对 subReports 也做同样的事情......

于 2017-06-23T09:38:10.133 回答