I don't know if what I am doing is the OSGi and Maven way, so first some background:
I have two bundles web
and client
. In the client bundle, I want to access a service that the web bundle registers. I have already checked that I can implement BundleContextAware
in the client bundle and if the web bundle's ArtifactId is project.web
then the following works:
public void setBundleContext(BundleContext bc) {
bc.getServiceReferences(clazz, "(Bundle-SymbolicName=project.web)")
What I would like to is not hard-code the symbolic name of the web bundle. The symbolic name comes from the artifactId
declared in pom.xml
, I believe by some gemini-blueprint magic. So my current thought is
- create a property
web.artifactId
in parent pom - in web bundle's pom use
<artifactId>${web.artifactId}</artifactId>
- somehow access that property in client bundle's
BundleContextAware.setBundleContext
How do I do this last step? I guess it might be possible to generate a java file at run-time that assigns the property value to some known identifier, so I can use WebBundleInfo.ARTIFACT_ID
; but I don't know how to do that and wonder if that is an overkill.
Another thought is if there is a way that the client bundle can use System.getProperty
to access this value? I saw some references to accessing a property file but I am not very keen on it -- neither on reading a property file, nor on generating it.
So my questions are: - Is this is a good way to share a bundle's symbolic-name like this? - Is there a away to automatically make some properties created in pom file available to the run-time execution environment? - I guess I could figure out how to generate such a source file, but is that a good way to solve this? Is there a way to generate such a file without a source file, i.e. from some text in the pom.xml itself? Further, is it possible to overwrite the existing file only if it has changed so as to avoid recompilation, because that will end up in a new snapshot version after every compile?