0

I have a NetBeans project in which I want to design jasper report, when I fill report via JasperFillManager.fillReport then I found an error message.

How can I resolve this?

I've used iReport 5.0.0 and JasperReports library 5.1.0.

my code is described below

try {
    String reportName = "./rptJobList.jasper";
    InputStream is = new FileInputStream(reportName);
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/js001?user=root&password=admin");
    JasperPrint jasperPrint = JasperFillManager.fillReport(is, null, con);
    JasperViewer jv = new JasperViewer(jasperPrint);
    jv.setVisible(true);
} catch (Exception ex) {
}

The exception is:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at net.sf.jasperreports.engine.util.JRLoader.(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.(DefaultJasperReportsContext.java:71) at net.sf.jasperreports.engine.DefaultJasperReportsContext.(DefaultJasperReportsContext.java:59) at net.sf.jasperreports.engine.JasperFillManager.getDefaultInstance(JasperFillManager.java:85) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:824) at job.NewClass.jButton2ActionPerformed(NewClass.java:64) at job.NewClass.access$000(NewClass.java:21) at job.NewClass$1.actionPerformed(NewClass.java:42) 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:6134) at javax.swing.JComponent.processMouseEvent(JComponent.java:3265) at java.awt.Component.processEvent(Component.java:5899) at java.awt.Container.processEvent(Container.java:2023) at java.awt.Component.dispatchEventImpl(Component.java:4501) at java.awt.Container.dispatchEventImpl(Container.java:2081) at java.awt.Component.dispatchEvent(Component.java:4331) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895) at java.awt.Container.dispatchEventImpl(Container.java:2067) at java.awt.Window.dispatchEventImpl(Window.java:2458) at java.awt.Component.dispatchEvent(Component.java:4331) 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.apache.commons.logging.LogFactory 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) ... 35 more

Alex K
  • 22,315
  • 19
  • 108
  • 236
Husain Sanwerwala
  • 479
  • 2
  • 7
  • 13
  • possible duplicate of [How to get .jasper file from .jrxml](http://stackoverflow.com/questions/16456033/how-to-get-jasper-file-from-jrxml) – Alex K Jun 17 '13 at 07:07

1 Answers1

0

Commons Logging needs to be added to the classpath. If you're working in a regular Netbeans project (and not in a Maven project in Netbeans) check out this SO question or this article that explain how to add libraries to a project.

If on the other hand you're working on a Maven project using Netbeans, Commons logging has to be added as a dependency. How that's done can be found here - basically it's a rightclick on the libraries node in the project tree, add dependency, enter artefact details or use the built-in search assistant to locate the correct artefact in the Maven repository.

Community
  • 1
  • 1
fvu
  • 32,488
  • 6
  • 61
  • 79
  • Of course, but as JasperReports needs Commons Logging (just follow the stack trace, it will be obvious) you need to include that library as well. Commons Logging may need other libraries as well (that ifo can probably be found on their website) or just add commons logging, try again, see what's missing, and so on until your program runs. – fvu Jun 14 '13 at 22:02