OSGi Bundle Both Imports and Exports the Same Package
In OSGi bundle, what will happen if you define a package in both Export-Package and Import-Package in the bnd configuration, and how can this lead to class loading issues?
In OSGi bundle, what will happen if you define a package in both Export-Package and Import-Package in the bnd configuration, and how can this lead to class loading issues?
Hi @mateuszno2,
When the same package is declared in both Export-Package and Import-Package of your OSGi bundle's bnd configuration, it creates a conflict between the bundle acting as a provider and simultaneously a consumer of that package.
Here is what happens:
OSGi will prefer the imported version if the same package is available from another bundle.
This may cause version mismatches, especially if the imported version differs from the local (exported) one.
It can also result in split packages, where classes from the same package are loaded by different classloaders, leading to ClassCastException, NoClassDefFoundError, or unexpected behavior.
Please refer below link for more details: https://techinnovia.com/package-import-and-export/
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.