I have a folder of existing bundled jars I need to use as declarative services. I'm aware of how to treat these like typical Eclipse Plugins and have them declared inside of the typical Component.xml file inside of my plugin project OSGI-INF folder, but now I'd like to follow the OSGI Enroute style of coding and load my bundles as Declarative Services inside there. It seems like services are added to the generated Component.xml for you with OSGI Enroute when you add the @Component annotation, but I'm struggling to figure out how to bring in my pre-existing bundles as Declarative Services since they don't have the annotations in them and I can't change their code (plus they don't have poms). Is there some intuitive way of solving this that I'm missing? Enroute seems like a great way to handle OSGI otherwise.
Asked
Active
Viewed 86 times
1 Answers
0
If I understood your question right, then:
- You have legacy bundles
- You can not change the code of those bundles
- Services with in those bundles are not Declarative Services (using the
@Component
annotation) - You want to have those services as Declarative Services
In that case you could write the XML files for the Declarative Services yourself:
- Add a new Maven module to your project
- Add the legacy bundle(s) as dependency
- Add the "hand-written" XML files for those services as sources to the module
- Let Maven unpack the legacy bundles
- Add the "hand-written" XML files to the new bundle with Maven
- Update the MANIFEST.MF of the bundle (if necessary)
- Package everything back to a OSGi bundle
In the end the @Component
annotation is just used to create XML files during the build describing your Declarative Service. If the code for those old service does not change anymore, it would be reasonable to write the XML files by hand.

Jens
- 20,533
- 11
- 60
- 86
-
Thanks for your response! I'm a little confused what you mean by having Maven "unpack" the bundles. Also, where would I add the hand-written XML file so that it's actually used? If I'm building a maven module, I assume it would only use what's built and a typical maven module doesn't have an OSGI-INF folder (or a MANIFEST.MF) till build time. – Snowday313 Jun 10 '19 at 15:46
-
@Snowday313 There are Maven plugins that you can use to "unpack" your Jars, like [maven-dependency-plugin](https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html). And then you could use plugins like the `maven-resource-plugin` to copy your hand-written XML files into the correct location in your resulting Jar. It is a little bit tricky, but doable. – Jens Jun 11 '19 at 07:39