pluginsosgiosgi-bundledeclarative-services

How to Add Existing Bundles as Declarative Services Within OSGI Enroute


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.


Solution

  • If I understood your question right, then:

    1. You have legacy bundles
    2. You can not change the code of those bundles
    3. Services with in those bundles are not Declarative Services (using the @Component annotation)
    4. You want to have those services as Declarative Services

    In that case you could write the XML files for the Declarative Services yourself:

    1. Add a new Maven module to your project
    2. Add the legacy bundle(s) as dependency
    3. Add the "hand-written" XML files for those services as sources to the module
    4. Let Maven unpack the legacy bundles
    5. Add the "hand-written" XML files to the new bundle with Maven
    6. Update the MANIFEST.MF of the bundle (if necessary)
    7. 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.