Programmatically changing OSGi bundle imports

Jeewantha

There is a common bundle (A) in my Equinox OSGi application which is used for a common task. But bundle A imports packages from many other bundles depending on circumstance. What I mean is, When Bundle A and Bundle B are in the runtime, A should import package "com.b.package1". When Bundle A and Bundle C are in the runtime, A should import package "com.c.package2". For this I have to change the import statement in MANIFEST.MF file in bundle A manually every time I want to change the runtime. Is there a way to handle this programatically. Maybe using a custom class loader in bundle A? Any help is appreciated.

Gunnar

To answer your question, it's not possible to create a custom bundle class loader in a framework independent way. However, there are alternatives available.

One possible way could be using dynamic imports. Then both packages can be accessed at runtime. Making both imports optional might also work.

You should also definitely look at OSGi services for your approach (or at Declarative Services).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related