FreakyDan FreakyDan - 1 year ago 112
Java Question

Importing Internal Packages in OSGI

I have recently begun converting existing maven projects to OSGI bundles and am confused about what all I need to list in the

tags in the POM file.

Initially I put an asterisk to see everything OSGI thought is need and was surprised to see that it was listing packages from the very same project. I have looked around online and have not been able to find a definitive answer to whether or not it is need to import internal packages and if there are potential issues that might arise down the road from not doing so.

Am I required to list used package from within the very project in
, and if so why as it seems unnecessary to me.

I am using the following plugin in the POM:


Here is the resulting pom for tx-core. All tx-core.* packages are from the project itself.

Manifest-Version: 1.0
Bundle-SymbolicName: tx-core
Archiver-Version: Plexus Archiver
Built-By: User
Bnd-LastModified: 1466089543997
Bundle-ManifestVersion: 2
Import-Package: cafe.crypto,tx.core,tx.core.conf,tx.core.conv,tx.core.
DynamicImport-Package: javax.*, org.xml.sax, org.xml.sax.*,org.w3c.*
Tool: Bnd-
Export-Package: cafe.crypto;version="4.0.1",tx.core;uses:="
Bundle-Name: tx-core
Bundle-Version: 4.0.1
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.8.0_77

Thank you for any and all assistance.

Answer Source

For packages internal to a given bundle, there is no need to import them. <Import-Packages> is used to indicate packages required across bundles.

Without seeing your POM/MANIFEST or knowing what Maven Plugin you are using for OSGi bundling, I'm not entirely sure why the asterisk would show all internal packages. I suspect that your POM/MANIFEST is using <Export-Packages> to export all your internal packages.