You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Olivier Roger <ol...@gmail.com> on 2010/09/29 17:13:22 UTC

[OSGi] NoClassDefFound with Spring ?

Hello ServiceMix,

I am currently trying to package my Camel route as an OSGi bundle to deploy
it in ServiceMix 4.

I have a strange behavior at runtime with my custom TypeConverter class
(used in camel to extends the available automated format convertion).

Its constructor uses the XBeanMessageMarshaller Bean declared in another
bundle. Since this other bundle is in fact a wrapped Jar, it exports all its
packages. My route bundle imports the package from XBeanMessageMarshaller.

As far as I can see from the stacktrace, Spring is apparently trying to
instantiate the bean from its own classloader, not the route one, which
results in a NoClassDefFoundException.

Here is the 
http://servicemix.396122.n5.nabble.com/file/n3025203/NoClassDefFound.txt
stacktrace .

Could someone explain me what is happening and how to solve this issue ?

Thanks in advance,

Olivier
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-NoClassDefFound-with-Spring-tp3025203p3025203.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [OSGi] NoClassDefFound with Spring ?

Posted by "Olivier.Roger" <ol...@bsb.com>.
I renamed the wrapped bundle into "messaging" so that the Import-Package is
simpler

<Import-Package>com.myCompany.sf.messaging.marshaller.xbean;bundle-symbolic-name="messaging",*</Import-Package> 

Using the headers command, the wrapped bundle has now the new Symbolic Name
but the Missing Constraint is still present.

Has the version something to do with this ? The spec seems to imply that the
default value is [0.0.0,infinite so I guess not...
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-NoClassDefFound-with-Spring-tp3025203p3072682.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [OSGi] NoClassDefFound with Spring ?

Posted by "Olivier.Roger" <ol...@bsb.com>.
I found the problem source.

It is quite simple actually... Two bundles export the same package
com.myCompany.sf.messaging.marshaller.xbean

This cause SMX to import only the first one, witch does not contain the
XBeanMessageMarshaller class.

This will be fixed of course,

In the meantime, I tried to force the package to import by setting the
bundle-symbolic-name option in <Import-Package>.

<Import-Package>com.myCompany.sf.messaging.marshaller.xbean;bundle-symbolic-name="wrap_mvn_mycompany-sf-messaging-base_1.0-SNAPSHOT",*</Import-Package>

At the moment is leads to a Missing Constraint: Import-Package:
com.myCompany.sf.messaging.marshaller.xbean; version="0.0.0"

Am I doing something wrong ?

-- 
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-NoClassDefFound-with-Spring-tp3025203p3072517.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [OSGi] NoClassDefFound with Spring ?

Posted by "Olivier.Roger" <ol...@bsb.com>.
Joe, 

You seem to be right about the missing dependency.
However, I already set the <DynamicImport-Package>*</DynamicImport-Package>
header which didn't change this behavior.

My guess is that the missing class is not exported by any of the active
bundle. I don't know what class it could be since the exception is so not
helpful. It is possible to have a more detailed error message ?

I already wrapped all of my project dependencies. 
The only dependency not wrapped is Spring, since the feature is enabled.
Could that be an issue ?
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-NoClassDefFound-with-Spring-tp3025203p3072432.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [OSGi] NoClassDefFound with Spring ?

Posted by Kévin Sailly <ke...@gmail.com>.
Hi,

Sorry it only works for XBean based service units.

Regards,
Kévin
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-NoClassDefFound-with-Spring-tp3025203p3047413.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [OSGi] NoClassDefFound with Spring ?

Posted by "Olivier.Roger" <ol...@bsb.com>.
Hello Kévin,

I'm not sure to understand why nor how I could use this feature.

If I understand correctly, adding this tag will tell SMX4.2 to add all the
classes from the wrapped package in the Camel route bundle. Which would make
them available at runtime.

However, I thought this was exactly the Import-Package role.

Also, I don't know where to put that tag in the camelContext, the schema
does not seems to validate with it.

I am really interested to understand better this features.
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-NoClassDefFound-with-Spring-tp3025203p3047245.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [OSGi] NoClassDefFound with Spring ?

Posted by Kévin Sailly <ke...@gmail.com>.
Hi,

Did you try adding this to you camel context route : 

<classpath>
  <library>osgi:com.myCompany.sf.messaging.marshaller.xbean</library>
</classpath>

(detail source here : http://servicemix.apache.org/classloaders.html)

Regards,
Kévin Sailly
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-NoClassDefFound-with-Spring-tp3025203p3047202.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [OSGi] NoClassDefFound with Spring ?

Posted by Joe Luo <jo...@ymail.com>.
It is a NoClassDefFoundError but not ClassNotFoundError. It looks like that the container classloader was able to find your com.myCompany.sf.messaging.marshaller.xbean.XBeanMessageMarshaller class but was not able to find some other classes that might have been defined/instantiated within your XbeanMessageMarsharller class. 

I'd make sure that all classes that defined in XBeanMessageMarshaller class are exported and your route bundle imports them (or try to use <DynamicImport-Package>*</DynamicImport-Package> header).

/Joe



Re: [OSGi] NoClassDefFound with Spring ?

Posted by "Olivier.Roger" <ol...@bsb.com>.
I am not sure, what is causing this issue.

To be sure I made the right import I added the following line in order to
let the bundle instantiate any class exported by loaded bundles.

DynamicImport-Package = *

Of course, I verified that the package of the class is exported by an Active
Bundle.
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-NoClassDefFound-with-Spring-tp3025203p3046647.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.