FreakyDan FreakyDan - 5 months ago 44
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

<Import-Packages>
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
<Import-Packages>
, and if so why as it seems unnecessary to me.

I am using the following plugin in the POM:

<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>


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.
production,tx.core.query,tx.core.util,javax.crypto,javax.crypto.spec,
javax.servlet
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
DynamicImport-Package: javax.*, org.xml.sax, org.xml.sax.*,org.w3c.*
Tool: Bnd-3.0.0.201509101326
Export-Package: cafe.crypto;version="4.0.1",tx.core;uses:="tx.core.pro
duction,tx.core.query";version="4.0.1",tx.core.conf;uses:="tx.core,tx
.core.production";version="4.0.1",tx.core.conv;version="4.0.1",tx.cor
e.identity;version="4.0.1",tx.core.io;uses:="tx.core,tx.core.producti
on";version="4.0.1",tx.core.notify;version="4.0.1",tx.core.production
;uses:="tx.core,tx.core.conv,tx.core.query";version="4.0.1",tx.core.q
uery;uses:="tx.core.conv";version="4.0.1",tx.core.util;version="4.0.1
",tx;version="4.0.1"
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

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.

Comments