Search code examples
osgiequinoxosgi-bundle

OSGi - modify a class in a bundle without modifying the original bundle


I have a need to modify a class in a OSGi bundle. But this bundle comes from an upstream project hence I cannot(/won't) touch it. But I have to modify a class in it to match my project's requirements. So, I'm looking for a solution for this.

So, I created my own bundle which has the patched classes. But there is a complication since the upstream OSGi bundle, and the patch OSGi bundle I created has the same packages. I want to over-ride the classes in the upstream OSGi bundle, without touching the it.

I looked at the osgi.org Fragment page. It suggests a way to patch a host bundle by using a fragment bundle, but for that I have to modify the upstream project bundle's MANIFEST.MF to set Bundle-ClassPath: patch.jar,.

Any suggestions?


Solution

  • You can implement a WeavingHook and catch the class loading of that bundle.

    However, do it only if you do not have any other chance to solve your problem. If you have any chance to contribute to that project that contains the jar, send a patch for them and have this only as a temporary solution. With hacks like this, your system will be chaotic for others.