You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by "tmkha@yahoo.com" <tm...@yahoo.com> on 2011/05/06 03:56:50 UTC

ClassNotFoundException problem which resolved after restarting Karaf

I have a service A instantiated by blueprint.    The constructor of service A
has reference to a static object in Class B in a different bundle. 
Blueprint kept on giving me java.lang.NoClassDefFoundError and
java.lang.ClassNotFoundException on Class B.

This seems to happen only on the first startup but resolves itself if I
restart Karaf.  It probably have to do with the fact that I prepare all the
bundles in the deploy directory without defining any feature.

I am running out of idea how to debug this issue.  Your help would be
greatly appreciated.

Regards,

- Triet

--
View this message in context: http://karaf.922171.n3.nabble.com/ClassNotFoundException-problem-which-resolved-after-restarting-Karaf-tp2906583p2906583.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: ClassNotFoundException problem which resolved after restarting Karaf

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

Yeah, using osgi service is preferred solution.

Freeman
On 2011-5-7, at 上午1:59, Achim Nierbeck wrote:

> Hi Triet,
>
> I guess it's ok but still a workaround.
> I strongly suggest you do refactor your application to use services
> instead of relying on
> packages/Classes of your second Bundle. If you reference Services  
> it's quite
> easy to make sure your "consumer" waits till the service is available.
>
> Regards, Achim
>> Thanks, Freeman.
>>
>> I created a feature including Bundle B giving a start-level of 50  
>> and set
>> the feature to be the first feature in the featuresBoot in
>> org.apache.karaf.features.cfg.  That seems to solve the problem.    
>> Is this a
>> solution I can rely on?
>>
>> Regards,
>>
>> Triet
>>
>> --
>> View this message in context: http://karaf.922171.n3.nabble.com/ClassNotFoundException-problem-which-resolved-after-restarting-Karaf-tp2906583p2908859.html
>> Sent from the Karaf - User mailing list archive at Nabble.com.
>

---------------------------------------------
Freeman Fang

FuseSource
Email:ffang@fusesource.com
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
Connect at CamelOne May 24-26
The Open Source Integration Conference









Re: ClassNotFoundException problem which resolved after restarting Karaf

Posted by Achim Nierbeck <bc...@googlemail.com>.
Hi Triet,

I guess it's ok but still a workaround.
I strongly suggest you do refactor your application to use services
instead of relying on
packages/Classes of your second Bundle. If you reference Services it's quite
easy to make sure your "consumer" waits till the service is available.

Regards, Achim
> Thanks, Freeman.
>
> I created a feature including Bundle B giving a start-level of 50 and set
> the feature to be the first feature in the featuresBoot in
> org.apache.karaf.features.cfg.  That seems to solve the problem.   Is this a
> solution I can rely on?
>
> Regards,
>
> Triet
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/ClassNotFoundException-problem-which-resolved-after-restarting-Karaf-tp2906583p2908859.html
> Sent from the Karaf - User mailing list archive at Nabble.com.


Re: ClassNotFoundException problem which resolved after restarting Karaf

Posted by "tmkha@yahoo.com" <tm...@yahoo.com>.
Thanks, Freeman.

I created a feature including Bundle B giving a start-level of 50 and set
the feature to be the first feature in the featuresBoot in
org.apache.karaf.features.cfg.  That seems to solve the problem.   Is this a
solution I can rely on?

Regards,

Triet

--
View this message in context: http://karaf.922171.n3.nabble.com/ClassNotFoundException-problem-which-resolved-after-restarting-Karaf-tp2906583p2908859.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: ClassNotFoundException problem which resolved after restarting Karaf

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

My comment inline
On 2011-5-6, at 下午1:16, tmkha@yahoo.com wrote:

> Hi Freeman,
>
> Thanks for the suggestion. Service A in Bundle A accesses a static  
> member of
> Class B in Bundle B, which does not export any service.  So as you  
> said,
> very likely Class B/Bundle B has not been loaded yet.  But Bundle A  
> has
> import for the package from Bundle B, shouldn't that force Bundle B  
> to be
> loaded before Bundle A?
No.
>
> If I restart Karaf, the problem is resolved by itself.  Is it  
> because Karaf
> reorganizes the start-up sequence or is it just a coincidence?
It's a timing issue, you can't rely on it.

Freeman
>
> Thanks,
> - Triet
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/ClassNotFoundException-problem-which-resolved-after-restarting-Karaf-tp2906583p2906937.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

---------------------------------------------
Freeman Fang

FuseSource
Email:ffang@fusesource.com
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
Connect at CamelOne May 24-26
The Open Source Integration Conference









Re: ClassNotFoundException problem which resolved after restarting Karaf

Posted by "tmkha@yahoo.com" <tm...@yahoo.com>.
Hi Freeman,

Thanks for the suggestion. Service A in Bundle A accesses a static member of
Class B in Bundle B, which does not export any service.  So as you said,
very likely Class B/Bundle B has not been loaded yet.  But Bundle A has
import for the package from Bundle B, shouldn't that force Bundle B to be
loaded before Bundle A?

If I restart Karaf, the problem is resolved by itself.  Is it because Karaf
reorganizes the start-up sequence or is it just a coincidence?

Thanks,
- Triet

--
View this message in context: http://karaf.922171.n3.nabble.com/ClassNotFoundException-problem-which-resolved-after-restarting-Karaf-tp2906583p2906937.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: ClassNotFoundException problem which resolved after restarting Karaf

Posted by Freeman Fang <fr...@gmail.com>.
Hi,
Let's say SerivceA is in BundleA, ClassB is in BundleB
This problem could be caused by BundleA start before BundleB, so the  
static Class B not get initialized at all when BundleA starting, this  
is a timing issue and your logic depend on bundles start sequence  
isn't a good practice in OSGi world.
How you reference ClassB in ServiceA? If you expose object in ClassB  
as an OSGi service and reference it in ServiceA, then BundleB will  
always get initialized firstly so you won't see this timing issue.

Freeman



On 2011-5-6, at 上午9:56, tmkha@yahoo.com wrote:

> I have a service A instantiated by blueprint.    The constructor of  
> service A
> has reference to a static object in Class B in a different bundle.
> Blueprint kept on giving me java.lang.NoClassDefFoundError and
> java.lang.ClassNotFoundException on Class B.
>
> This seems to happen only on the first startup but resolves itself  
> if I
> restart Karaf.  It probably have to do with the fact that I prepare  
> all the
> bundles in the deploy directory without defining any feature.
>
> I am running out of idea how to debug this issue.  Your help would be
> greatly appreciated.
>
> Regards,
>
> - Triet
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/ClassNotFoundException-problem-which-resolved-after-restarting-Karaf-tp2906583p2906583.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

---------------------------------------------
Freeman Fang

FuseSource
Email:ffang@fusesource.com
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
Connect at CamelOne May 24-26
The Open Source Integration Conference