At OSGi, you'll want to stay away from thinking for the reasons outlined in many other places.
So your situation is that package A requires some instance of the class that is in package B For A to understand this instance, I assume that it has some interface that it will use to talk to the instance. Let me make it a little more specific.
/Bundle A /ThingyInterface.class /Bundle B /ThingyImplementation.class (implements ThingyInterface.class)
This is a regular template: one package provides an interface, and the other provides an implementation. Now two situations are possible:
A requires exactly one copy of the implementation. In this case, register Thingy as a service.A few instances of the implementation are required. In this case, enter ThingyFactory in A and create an implementation of this factory in B , which then registers as a service.
In any case, you allow B to actually create the instance, you have no dependency on A to B , and B does not need reflection to create the objects.
In short, services are your friend.
source share