Hi,

if I understand you correctly you have an optional package import to the
package providing BarService?

In that case your class SomeComponent can't be loaded if that package is
not available and there is no magic to get around this.

Regards

Carsten


Osgi Developer Mail List wrote
> Hi,
> 
> I have an SCR component that references a service, with 0...1
> cardinality. That service is part of an optional import. The aim is
> that if the package is available at runtime, the reference is bound,
> otherwise not, but the component functions without it, e.g.
> 
> 
> @Component public class SomeComponent {
> 
> @Reference private FooService foo;
> 
> @Reference(cardinality = OPTIONAL_UNARY ) private BarService bar;
> 
> }
> 
> The result though is that the component bind method lookups fail, e.g.:
> 
> Failure loooking up method
> bindFoo(org.osgi.framework.ServiceReference) in class
> com.example.SomeComponent. Assuming no such method.
> (java.lang.NoClassDefFoundError: com/example/optional/BarService)
> 
> What's interesting is that the 'foo' reference is not part of an
> optional import, the class is visible and the reference is there.
> Obviously in this scenario the optional import for BarService is not
> satisfied and the class it not available.
> 
> I'm running org.apache.felix.scr from the latest OSGi-r7 folder -
> https://svn.apache.org/repos/asf/felix/trunk/osgi-r7/scr/ .
> 
> So my questions are:
> 
> 1. Is this scenario something that SCR can support?
> 2. If the answer above is no, what is the best way of achieving the
> result? Splitting the bundle is unfortunately quite tedious so I'd
> like to avoid that.
> 
> Thanks,
> 
> Robert
> 
-- 
Carsten Ziegeler
Adobe Research Switzerland
cziege...@apache.org
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to