JasperReports:获取“java.lang.NoClassDefFoundError:org/slf4j/LoggerFactory”异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20584798/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:56:24  来源:igfitidea点击:

JasperReports: getting "java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory" Exception

javajasper-reportsnoclassdeffounderrorclassnotfoundexception

提问by Dimi

I have created a report (JasperReports 5.5) using the JasperReports pluginfor NetBeans 6.9.1(Java 1.6). I can create a report and the report can be successfully viewed using the Preview tab of the JasperReports Plugin. But when I use Javacode to access the report it gives the following Error:

我创建了一个报告(JasperReports的5.5使用)的JasperReports插件的NetBeans 6.9.1Java 1.6的)。我可以创建一个报告,并且可以使用JasperReports Plugin的 Preview 选项卡成功查看该报告。但是当我使用Java代码访问报告时,它给出了以下错误:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:131)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272)
    at net.sf.jasperreports.engine.util.JRLoader.<clinit>(JRLoader.java:68)
    at net.sf.jasperreports.engine.JRPropertiesUtil.loadProperties(JRPropertiesUtil.java:99)
    at net.sf.jasperreports.engine.DefaultJasperReportsContext.initProperties(DefaultJasperReportsContext.java:94)
    at net.sf.jasperreports.engine.DefaultJasperReportsContext.<init>(DefaultJasperReportsContext.java:71)
    at net.sf.jasperreports.engine.DefaultJasperReportsContext.<clinit>(DefaultJasperReportsContext.java:59)
    at net.sf.jasperreports.engine.JasperCompileManager.getDefaultInstance(JasperCompileManager.java:84)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:459)
    at Interfaces.MainMenu.jMenuItem3ActionPerformed(MainMenu.java:854)
    at Interfaces.MainMenu.access00(MainMenu.java:50)
    at Interfaces.MainMenu.actionPerformed(MainMenu.java:494)
    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.AbstractButton.doClick(AbstractButton.java:357)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:809)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:850)
    at java.awt.Component.processMouseEvent(Component.java:6288)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6053)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4651)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4481)
    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:4481)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
    at java.awt.EventQueue.access
try {
        String report = "C:\Users\Admin\Documents\WarrantReport.jrxml";
        JasperReport jr = JasperCompileManager.compileReport(report);
        JasperPrint jp = JasperFillManager.fillReport(jr, null, c);
        JasperViewer.viewReport(jp);
    } catch (JRException ex) {
        Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
    }
0(EventQueue.java:84) at java.awt.EventQueue.run(EventQueue.java:602) at java.awt.EventQueue.run(EventQueue.java:600) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext.doIntersectionPrivilege(AccessControlContext.java:87) at java.security.AccessControlContext.doIntersectionPrivilege(AccessControlContext.java:98) at java.awt.EventQueue.run(EventQueue.java:616) at java.awt.EventQueue.run(EventQueue.java:614) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:613) 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.slf4j.LoggerFactory at java.net.URLClassLoader.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 51 more

When I add the mentioned JAR file it gives the same error with a different JAR and it goes on and on.

当我添加提到的 JAR 文件时,它会使用不同的 JAR 给出相同的错误,并且它会继续下去。

I have used the following code to access the report.

我已使用以下代码访问报告。

##代码##

I have added the following 5 JAR files to my Project folder Libraries:
jasperreports 5.5 applet, fonts, functions, javaflow.

我已将以下 5 个 JAR 文件添加到我的项目文件夹库中:
jasperreports 5.5 applet、fonts、functions、javaflow。

Please help me find the error.

请帮我找出错误。

回答by Gaurav Varma

A NoClassDefFoundErrorwith ClassNotFoundExceptionspecifies that the particular class is missing during runtime. For the LoggerFactoryto be available you should have any of these jarsin your classpath.

一个NoClassDefFoundErrorClassNotFoundException该特定类是运行过程中缺少指定。为了使LoggerFactory可用,您的类路径中应该有这些 jar中的任何一个。

You can further debug a NoClassDefFoundError here

您可以在此处进一步调试 NoClassDefFoundError