I have defined an OSGi bundle (cluster_implementation
) with a Declarative Service (DS) component definition, specifying one service exported, one activate method and one deactivate method.
In the body of the Activate method i need to access one file that is not present in the file-system but is bundled in the OSGi bundle itself.
During the activate method, the file content is retrieved as an InputStream
using java.lang.ClassLoader:getResourceAsStream
.
This mostly works, but there is one case where it doesn't work. In my application the service exported by the cluster_implementation
can be referenced by other bundles either via the Service Registry or Declarative Service or spring-dm. The activation policy of the component is delayed
so it gets activated when the first reference to the service happens.
Now if the activation happens because of a reference from Declarative Service component the file content is read fine, if instead the activation happens because a spring-dm component is in the need for the service, then the InputStream
for the resource is NULL
!
For now i have solved the problem by making the component to activate immediately by setting immediate="true"
in the component property, however my requests are these:
Bundle.findEntries
I can see it!The OSGi framework I'm using is Equinox 3.6.
I think you must have another problem than you think. Access to resources is available to any resolved bundle and is completely unrelated to DS. Since your class is loaded, your code can be loaded from the JAR.
The behavior seems puzzling, and maybe an error in the framework. I could only imagine this going wrong when you use fragments? But even that does not seem to make sense. Did you try another framework, Felix has very good diagnostics.