JasperReports应用程序抛出NoClassDefFoundError:net / sf / jasperreports / engine / JasperCompileManager

时间:2012-02-06 10:43:01

标签: eclipse jasper-reports rcp

我有一个带有图形编辑框架的项目,它是一个RCP应用程序,我想将JasperReports集成到我的项目中,但是在运行它时会出现错误:

java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JasperCompileManager

我导入了它,但我不知道为什么运行时找不到它:

import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.view.JasperViewer;

Plz告诉我我错过了哪些罐子 这是我的java代码:

    JasperReport jasperReport;
    JasperPrint jasperPrint;
    try {
        Map<String, Object> parameters = new HashMap<String, Object>();
        jasperReport = (JasperReport) JRLoader.loadObject(new File("C:/Users/Alex/JaspersoftWorkspace/MyReports/Balcony.jasper"));
        jasperReport = JasperCompileManager.compileReport("C:/Users/Alex/JaspersoftWorkspace/MyReports/Balcony.jrxml");
        //  JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(wrapperPojoList);
        JRBeanCollectionDataSource ds = null;
        jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JasperExportManager.exportReportToPdfFile(jasperPrint, "C:/Users/Alex/Desktop/sampleReport.pdf");
        JasperViewer.viewReport(jasperPrint);
        // writeExportToResponseStream(outputStream, baos);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e);
    }

这是RCP应用程序,当我作为eclipse应用程序运行时,我在控制台上遇到错误:

java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JasperCompileManager
at com.itfarm.shapes.actions.Calculation.run(Calculation.java:205)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: java.lang.ClassNotFoundException: net.sf.jasperreports.engine.JasperCompileManager
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 31 more

1 个答案:

答案 0 :(得分:0)

有时,如果使用iReport Designer工具,当iReport版本与jasperreports-x.x.x.jar不一致时会出现此问题