Reputation: 569
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.
Upvotes: 0
Views: 2810
Reputation: 26
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-Package>
to export all your internal packages.
Update From the Apache Felix Maven Bundle Plugin Docs:
<Import-Package>
is assumed to be "*", which imports everything referred to by the bundle content, but not contained in the bundle. Any exported packages are also imported by default, to ensure a consistent class space.
See Should a bundle import its own exported packages? for a description of why this happens.
By default, if <Export-Package>
isn't explicitly defined, then all of your packages (with exceptions) are exported and then re-imported:
<Export-Package>
is now assumed to be the set of packages in your local Java sources, excluding the default package '.' and any packages containing 'impl' or 'internal'.
For packages internal to your bundle, if you don't intend for other bundles to be able to reference them, you have 2 choices:
<Export-Package>
<Private-Package>
Upvotes: 1
Reputation: 23958
You don't need to write an <Import-Package>
header at all. The default value is "*" which means "import all packages that are referenced by the code in the bundle but don't actually appear in the bundle".
If this is generating "internal" packages as imports then they are not internal packages, i.e. for some reason they are not being included in the bundle. Would need to see more of the project structure to diagnose this issue.
Upvotes: 1