Question

I understand that OSGi can be used to manage service dependencies, that is sharing POJO instances between bundles. But say I have a library B.jar with compile-time dependencies on classes in my other library A.jar:

ProjectA/src/com/example/awesome/A.java:

package com.example.awesome;
public class A {}

ProjectB/src/com/example/awesome/web/B.java:

package com.example.awesome.web;
import com.example.awesome;
public class B extends A {}

Does OSGi have a built-in declarative way to enforce this dependency at runtime?

Was it helpful?

Solution

Yes, using the Export-Package and Import-Package manifest headers.

If you use an automated build system, it might detect the relationship and add these headers for you. Both Maven and Gradle use bnd to generate the necessary manifest headers. The bnd integration is provided by the maven-bundle-plugin and the Gradle OSGi plugin, respectively.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top