You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Morten <mo...@yahoo.dk> on 2010/05/23 23:12:28 UTC

problem: getResources("META-INF/services/..") does not return all from imported bundles?

I am trying to see if I can get felix to work with the javax.scripting api which looks for scripting implementations using classloader.getResources("META-INF/services/javax.script.ScriptEngineFactory").

The classloader can be specified to use the classloader for my bundle and I have tried to require all the (jruby) scripting api bundle directly using Require-Bundle. 

Unfortunately, even though Require-Bundle let's me access the jruby classes inside the jruby bundle, the getResources call won't properly lookup non-java resources such as files under "META-INF/services". It appears that felix Require-Bundle only work with java classes in packages - not files inside the imported bundle ?

Any advice ?

/Morten






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


Re: problem: getResources("META-INF/services/..") does not return all from imported bundles?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 5/23/10 18:51, Morten wrote:
> --- Den man 24/5/10 skrev Richard S. Hall<he...@ungoverned.org>:
>    
>> Fra: Richard S. Hall<he...@ungoverned.org>
>>      
>   >
>    
>> No, it doesn't. That's what I am saying, the spec doesn't
>> support it.
>> However, the Felix framework impl doesn't do anything to
>> prevent it.
>>      
> Ok, I understand your point now.
>
>    
>>> Yes, that is what I am afraid of. It seems the OSGI
>>>        
>> guys did not think about resources - only classes ? (So
>> require bundle does not in fact import everything - only the
>> classes).
>>      
>>>        
>> That is not accurate. Resources inside of packages are
>> handled just
>> fine, only resources not in packages are not handled. It
>> would be
>> difficult to do otherwise, since there is no naming
>> convention for
>> resources outside of packages that would not result in
>> naming collisions
>> or split "packages" all over the place.
>>      
> OK, but this requirement just means that it is extra hard to get non-OSGI jars to work with OSGI as many, many libraries has extra resources in non-package dirs.
>    

Agreed. Unfortunately, it just not possible to port all legacy 
mechanisms without changes, but luckily for most cases there are 
workarounds.

>>> Yes, I am also thinking about extender patteren. The
>>>        
>> problem is that jruby uses many more non-class resources
>> that will also not work with classloader.getRessources. So
>> after registering, JRuby will fail later on when trying to
>> load its *.rb files etc.
>>     
>> Perhaps so. I'm not familiar enough with it to know.
>>      
> Latest update: I got my final experimentation to work not by writing an extender but by creating a bridge classloader between my bundle and the jruby bundle which overloaded getResources to lookup using classloaders of both bundles.
>
> Works fine as far as I can tell but I have only tested it a few minutes - hopefully it will continue to work with more complex examples.
>    

Yeah, sounds reasonable.

> P.S: I bought your book. Very informative! Thanks for writing it.
>    

Excellent. Thanks for buying it. The final editing is well underway, so 
hopefully you'll get your final version this Summer...finally! :-)

-> richard

> /Cheers
> Morten
>
>
>
>
> ---------------------------------------------------------------------
> 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: problem: getResources("META-INF/services/..") does not return all from imported bundles?

Posted by Morten <mo...@yahoo.dk>.
--- Den man 24/5/10 skrev Richard S. Hall <he...@ungoverned.org>:
> Fra: Richard S. Hall <he...@ungoverned.org>
 > 
> No, it doesn't. That's what I am saying, the spec doesn't
> support it. 
> However, the Felix framework impl doesn't do anything to
> prevent it.

Ok, I understand your point now.

> > Yes, that is what I am afraid of. It seems the OSGI
> guys did not think about resources - only classes ? (So
> require bundle does not in fact import everything - only the
> classes).
> >
> 
> That is not accurate. Resources inside of packages are
> handled just 
> fine, only resources not in packages are not handled. It
> would be 
> difficult to do otherwise, since there is no naming
> convention for 
> resources outside of packages that would not result in
> naming collisions 
> or split "packages" all over the place.

OK, but this requirement just means that it is extra hard to get non-OSGI jars to work with OSGI as many, many libraries has extra resources in non-package dirs.
     
> > Yes, I am also thinking about extender patteren. The
> problem is that jruby uses many more non-class resources
> that will also not work with classloader.getRessources. So
> after registering, JRuby will fail later on when trying to
> load its *.rb files etc.
>     
> Perhaps so. I'm not familiar enough with it to know.

Latest update: I got my final experimentation to work not by writing an extender but by creating a bridge classloader between my bundle and the jruby bundle which overloaded getResources to lookup using classloaders of both bundles.

Works fine as far as I can tell but I have only tested it a few minutes - hopefully it will continue to work with more complex examples. 

P.S: I bought your book. Very informative! Thanks for writing it.

/Cheers
Morten




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


Re: problem: getResources("META-INF/services/..") does not return all from imported bundles?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 5/23/10 18:32, Morten wrote:
> --- Den man 24/5/10 skrev Richard S. Hall<he...@ungoverned.org>:
>    
>> Fra: Richard S. Hall<he...@ungoverned.org>
>> Emne: Re: problem: getResources("META-INF/services/..") does not return all from imported bundles?
>> If the required bundle exports META-INF/services, then it
>> should work.
>>      
> What is the syntax for exporting resources ? Does OSGI specify inport/export of non-java package stuff at all ?
>    

No, it doesn't. That's what I am saying, the spec doesn't support it. 
However, the Felix framework impl doesn't do anything to prevent it.

>> However, technically, OSGi only supports exporting packages
>> and
>> META-INF/services is not a package so it is not supposed to
>> work.
>>      
> Yes, that is what I am afraid of. It seems the OSGI guys did not think about resources - only classes ? (So require bundle does not in fact import everything - only the classes).
>    

That is not accurate. Resources inside of packages are handled just 
fine, only resources not in packages are not handled. It would be 
difficult to do otherwise, since there is no naming convention for 
resources outside of packages that would not result in naming collisions 
or split "packages" all over the place.

>>> Any advice ?
>>>        
>> Typically, the approach is to use the extender pattern to
>> listen for
>> META-INF/services and then somehow register the provider so
>> it can be used.
>>      
> Yes, I am also thinking about extender patteren. The problem is that jruby uses many more non-class resources that will also not work with classloader.getRessources. So after registering, JRuby will fail later on when trying to load its *.rb files etc.
>    

Perhaps so. I'm not familiar enough with it to know.

-> richard

> Thanks for your answer!
>
> /Morten
>
>
>
>
> ---------------------------------------------------------------------
> 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: problem: getResources("META-INF/services/..") does not return all from imported bundles?

Posted by Morten <mo...@yahoo.dk>.
--- Den man 24/5/10 skrev Richard S. Hall <he...@ungoverned.org>:
> Fra: Richard S. Hall <he...@ungoverned.org>
> Emne: Re: problem: getResources("META-INF/services/..") does not return all from imported bundles?
> If the required bundle exports META-INF/services, then it
> should work.

What is the syntax for exporting resources ? Does OSGI specify inport/export of non-java package stuff at all ?

> However, technically, OSGi only supports exporting packages
> and 
> META-INF/services is not a package so it is not supposed to
> work.

Yes, that is what I am afraid of. It seems the OSGI guys did not think about resources - only classes ? (So require bundle does not in fact import everything - only the classes).

> > Any advice ?
> Typically, the approach is to use the extender pattern to
> listen for 
> META-INF/services and then somehow register the provider so
> it can be used.

Yes, I am also thinking about extender patteren. The problem is that jruby uses many more non-class resources that will also not work with classloader.getRessources. So after registering, JRuby will fail later on when trying to load its *.rb files etc.

Thanks for your answer!

/Morten




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


Re: problem: getResources("META-INF/services/..") does not return all from imported bundles?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 5/23/10 17:12, Morten wrote:
> I am trying to see if I can get felix to work with the javax.scripting api which looks for scripting implementations using classloader.getResources("META-INF/services/javax.script.ScriptEngineFactory").
>
> The classloader can be specified to use the classloader for my bundle and I have tried to require all the (jruby) scripting api bundle directly using Require-Bundle.
>
> Unfortunately, even though Require-Bundle let's me access the jruby classes inside the jruby bundle, the getResources call won't properly lookup non-java resources such as files under "META-INF/services". It appears that felix Require-Bundle only work with java classes in packages - not files inside the imported bundle ?
>    

If the required bundle exports META-INF/services, then it should work. 
However, technically, OSGi only supports exporting packages and 
META-INF/services is not a package so it is not supposed to work.

> Any advice ?
>    

Typically, the approach is to use the extender pattern to listen for 
META-INF/services and then somehow register the provider so it can be used.

-> richard

> /Morten
>
>
>
>
>
>
> ---------------------------------------------------------------------
> 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