You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Peter Cheung <mc...@hotmail.com> on 2013/10/13 22:54:32 UTC

questions about felix

Dear All   I have a standalone java app that embedded felix. I can start it, load bundle and call the method from bundle (using reflection). 1) My first question is, using reflection is not efficiency.  I imported the class from bundle to my host app, it popup "ClassCastException", because i cannot cast a class that loaded from felix to a class that loaded from default class loader, even two classes are the same. Any workaround?2) I am using maven, how to i add bundle dependency to pom.xml?  pom.xml seems not searching the felix bundle repository. 

Thanksfrom Peter 		 	   		  

RE: questions about felix

Posted by Peter Cheung <mc...@hotmail.com>.
Hi All   I finally fixed the issues, i have to load the host app into felix first, after that i don't meet the class-casting error.

Thanksfrom Peter

> From: mcheung63@hotmail.com
> To: users@felix.apache.org
> Subject: RE: questions about felix
> Date: Tue, 15 Oct 2013 17:19:00 +0800
> 
> Thanks Marcel and Bruce     I dont know how to share the interface between my app and bundle, do you have a working example?
> So far my app (embedded felix) can load a bundle and call a function (in bundle) by reflection, but it is very very inconvenience. I have searched google, seems no work around. Any idea?
> Suppose i am developing a bundle rely on another bundle, how can i import that bundle to my maven project? Really can't find anything in google too, please help.
> 
> Thanksfrom Peter
> 
> > Subject: Re: questions about felix
> > From: marcel.offermans@luminis.nl
> > Date: Sun, 13 Oct 2013 23:55:58 +0200
> > To: users@felix.apache.org
> > 
> > On Oct 13, 2013, at 22:54 PM, Peter Cheung <mc...@hotmail.com> wrote:
> > 
> > > Dear All   I have a standalone java app that embedded felix. I can start it, load bundle and call the method from bundle (using reflection). 1) My first question is, using reflection is not efficiency.  I imported the class from bundle to my host app, it popup "ClassCastException", because i cannot cast a class that loaded from felix to a class that loaded from default class loader, even two classes are the same. Any workaround?2) I am using maven, how to i add bundle dependency to pom.xml?  pom.xml seems not searching the felix bundle repository. 
> > 
> > You cannot "see" classes that are loaded as part of bundles from your app. It does not help to duplicate them either. The best option is to create an interface, add that to your application, expose it as an exported package through the system bundle, and have the class in the bunde import and implement this interface. That way the interface is shared between the app and any bundle that imports it.
> > 
> > Hope that helps.
> > 
> > Greetings, Marcel
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> > For additional commands, e-mail: users-help@felix.apache.org
> > 
>  		 	   		  
 		 	   		  

RE: questions about felix

Posted by Peter Cheung <mc...@hotmail.com>.
Thanks Marcel and Bruce     I dont know how to share the interface between my app and bundle, do you have a working example?
So far my app (embedded felix) can load a bundle and call a function (in bundle) by reflection, but it is very very inconvenience. I have searched google, seems no work around. Any idea?
Suppose i am developing a bundle rely on another bundle, how can i import that bundle to my maven project? Really can't find anything in google too, please help.

Thanksfrom Peter

> Subject: Re: questions about felix
> From: marcel.offermans@luminis.nl
> Date: Sun, 13 Oct 2013 23:55:58 +0200
> To: users@felix.apache.org
> 
> On Oct 13, 2013, at 22:54 PM, Peter Cheung <mc...@hotmail.com> wrote:
> 
> > Dear All   I have a standalone java app that embedded felix. I can start it, load bundle and call the method from bundle (using reflection). 1) My first question is, using reflection is not efficiency.  I imported the class from bundle to my host app, it popup "ClassCastException", because i cannot cast a class that loaded from felix to a class that loaded from default class loader, even two classes are the same. Any workaround?2) I am using maven, how to i add bundle dependency to pom.xml?  pom.xml seems not searching the felix bundle repository. 
> 
> You cannot "see" classes that are loaded as part of bundles from your app. It does not help to duplicate them either. The best option is to create an interface, add that to your application, expose it as an exported package through the system bundle, and have the class in the bunde import and implement this interface. That way the interface is shared between the app and any bundle that imports it.
> 
> Hope that helps.
> 
> Greetings, Marcel
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 
 		 	   		  

RE: questions about felix

Posted by Stijn de Witt <St...@planonsoftware.com>.
>> i cannot cast a class that loaded from felix to a class that loaded from default class loader, even two classes are the same.

Actually, the classes are not the same. This is weird, but Java defines the identity of a class as the combination of the fully qualified classname + the classloader through which the class is loaded. So classes from different classloaders are always treated as different.

Either move the stuff that needs the class to a bundle that imports the class (probably very difficult) or do what Marcel suggested and make a common interface that is then exported as a framework package.

-Stijn


-----Original Message-----
From: Marcel Offermans [mailto:marcel.offermans@luminis.nl] 
Sent: zondag 13 oktober 2013 23:56
To: users@felix.apache.org
Subject: Re: questions about felix

On Oct 13, 2013, at 22:54 PM, Peter Cheung <mc...@hotmail.com> wrote:

> Dear All   I have a standalone java app that embedded felix. I can start it, load bundle and call the method from bundle (using reflection). 1) My first question is, using reflection is not efficiency.  I imported the class from bundle to my host app, it popup "ClassCastException", because i cannot cast a class that loaded from felix to a class that loaded from default class loader, even two classes are the same. Any workaround?2) I am using maven, how to i add bundle dependency to pom.xml?  pom.xml seems not searching the felix bundle repository. 

You cannot "see" classes that are loaded as part of bundles from your app. It does not help to duplicate them either. The best option is to create an interface, add that to your application, expose it as an exported package through the system bundle, and have the class in the bunde import and implement this interface. That way the interface is shared between the app and any bundle that imports it.

Hope that helps.

Greetings, Marcel


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: questions about felix

Posted by Marcel Offermans <ma...@luminis.nl>.
On Oct 13, 2013, at 22:54 PM, Peter Cheung <mc...@hotmail.com> wrote:

> Dear All   I have a standalone java app that embedded felix. I can start it, load bundle and call the method from bundle (using reflection). 1) My first question is, using reflection is not efficiency.  I imported the class from bundle to my host app, it popup "ClassCastException", because i cannot cast a class that loaded from felix to a class that loaded from default class loader, even two classes are the same. Any workaround?2) I am using maven, how to i add bundle dependency to pom.xml?  pom.xml seems not searching the felix bundle repository. 

You cannot "see" classes that are loaded as part of bundles from your app. It does not help to duplicate them either. The best option is to create an interface, add that to your application, expose it as an exported package through the system bundle, and have the class in the bunde import and implement this interface. That way the interface is shared between the app and any bundle that imports it.

Hope that helps.

Greetings, Marcel


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: questions about felix

Posted by Bruce Jackson <Br...@myriadgroup.com>.
Peter

This doesn't sound like the correct approach to be taking. If you load
bundles into felix, then they will be within the scope of their own class
loaded, per the OSGi model, and therefore not 'the same class'.

Thanks

Bruce

On 13/10/2013 21:54, "Peter Cheung" <mc...@hotmail.com> wrote:

>Dear All   I have a standalone java app that embedded felix. I can start
>it, load bundle and call the method from bundle (using reflection). 1) My
>first question is, using reflection is not efficiency.  I imported the
>class from bundle to my host app, it popup "ClassCastException", because
>i cannot cast a class that loaded from felix to a class that loaded from
>default class loader, even two classes are the same. Any workaround?2) I
>am using maven, how to i add bundle dependency to pom.xml?  pom.xml seems
>not searching the felix bundle repository.
>
>Thanksfrom Peter

*** DISCLAIMER ***

This message, including attachments, is intended solely for the addressee indicated in this message and is strictly confidential or otherwise privileged. If you are not the intended recipient (or responsible for delivery of the message to such person) : - (1) please immediately (i) notify the sender by reply email and (ii) delete this message and attachments, - (2) any use, copy or dissemination of this transmission is strictly prohibited. If you or your employer does not consent to Internet email messages of this kind, please advise Myriad Group AG by reply e-mail immediately. Opinions, conclusions and other information expressed in this message are not given or endorsed by Myriad Group AG unless otherwise indicated by an authorized representative independent of this message.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org