Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

OSGi Bundle Both Imports and Exports the Same Package

Avatar

Level 2

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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/


Santosh Sai

AEM BlogsLinkedIn


View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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/


Santosh Sai

AEM BlogsLinkedIn