Jump to content
We've recently updated our Privacy Statement, available here ×

Can't load report using osgi


fsf_matt

Recommended Posts

Hi all,

I've been developing a modular osgi application which uses JasperReports. Each report is deployed as a bundle, so the user can choose which reports they want. Each bundle is in the form of a jar. These jars contain: the *.jasper file for the report, as a resource; a class to supply information about the report (report name, description etc.) and some classes to take data from the main part of the application, analyse it and fill the report with it. The application has a launcher, which has equinox on its classpath, this instantiates an osgi framework, loads all the jars in a folder called "plugins" into the framework as bundles, then starts the bundles. Each part of the application is a bundle, one of them is the "main" bundle that contains the swing gui and core components, most of the rest are osgified libraries (eg. JasperReports, commons_logging etc.), a few contain common interfaces and there is one for each report.

This all worked very well, up until I started packaging the thing together ready for release, with the finished version, when you create a report it hangs. After some searching I found that it was blocking on a call to ObjectInputStream.readObject(), which I was using to read the JasperReport object from the *.jasper file in the report bundle. I also tried using JRLoader with no success, after looking at the source I found it uses ObjectInputStream.readObject() too, so that explains that.

The odd thing is that none of this happens when I run the equinox from Eclipse, it happily exports reports to pdf. I initially thought that having the bundles running from inside eclipse was making it behave differently but I also tried running the launcher from eclipse, with the launcher loading the exported jar bundles from the "plugins" folder like in the release, this also works perfectly. I've spent the last 2 days trying all sorts of things, the same problem happens if i try to load a *jrxml with JRXmlLoader, I also tried serializing the JasperReport object using XML with XStream and loading it using that, same problem. The bundle is capable of loading objects of other classes using ObjectInputStream.readObject() and is capable of reading bytes from the *.jasper. I would have thought it was a classpath or classloader problem caused by osgi, but given that it works in Eclipse and doesn't throw an exception I don't know what to think.

I haven't seen much evidence of people combining JasperReports and osgi but I really hope someone can help me with this, it's driving me mad.

Thanks.

Matt.

Code:

Edit-------------------------------------------------

 

I have now found that ObjectInputStream.readObject() is not blocking, I changed the last catch block to catch a Throwable and it now catches a NoClassDefFoundError, caused by a ClassNotFoundException, for org.apache.commons.logging.Log.

Here is the stack trace:

java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Unknown Source)
    at java.lang.Class.getDeclaredField(Unknown Source)
    at java.io.ObjectStreamClass.getDeclaredSUID(Unknown Source)
    at java.io.ObjectStreamClass.access$700(Unknown Source)
    at java.io.ObjectStreamClass$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.io.ObjectStreamClass.<init>(Unknown Source)
    at java.io.ObjectStreamClass.lookup(Unknown Source)
    at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readArray(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.defaultReadObject(Unknown Source)
    at net.sf.jasperreports.engine.base.JRBaseDataset.readObject(JRBaseDataset.java:401)
    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 java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.defaultReadObject(Unknown Source)
    at net.sf.jasperreports.engine.base.JRBaseReport.readObject(JRBaseReport.java:812)
    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 java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at report.ChildAssessmentReportGenerator.loadReport(ChildAssessmentReportGenerator.java:160)
    at report.ChildAssessmentReportGenerator.makeReport(ChildAssessmentReportGenerator.java:78)
    at gui.reportscreen.ReportPanel.actionPerformed(ReportPanel.java:298)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.Log
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:448)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 72 more

 

I have now added the package org.apache.commons.logging to the Import-Package block of the manifest of ALL of the bundles, which has had no effect, I also added the commons logging jar to the classpath of the launcher, to no effect. I find it really confusing dealing with these osgi stack traces as I can't tell which bundle has thrown which exception.

Any Ideas?



Post Edited by fsf_matt at 04/28/2010 09:08
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...