Reputation: 5419
I'm making my first steps in osgi bundle development using maven (maven-bundle-plugin) and apache karaf. My question is: How can i import packages of another bundle?
If I have two bundles A and B. Lets say Bundle A exports a package "package.from.bundle.A". This i can declare in the pom.xml of Bundle A Project:
...
<instructions>
...
<Export-Package>
package.from.bundle.A*;version=${project.version}
</Export-Package>
<Import-Package>
*
</Import-Package>
</instructions>
...
But how can i declare that i want to use that package in Bundle B? If I simply write the packagename between the import-package tag of project B's pom file, this does not work...
...
<instructions>
...
<Export-Package>
</Export-Package>
<Import-Package>
package.from.bundle.A
</Import-Package>
</instructions>
...
How does maven know from to which bundle project this package is related to? How can i use dependencies between my bundles using maven?
thank you
Upvotes: 1
Views: 581
Reputation: 19626
You have to set the maven dependencies to all bundles you need. This is necessary for the compile step in maven. The maven bundle plugin or bnd under the cover will then analyse the build result. It automatically detected all packages you provide and exports them unless they have some names like impl in them. It also detects all packages you import and creates Import-Package statements for them. So in most cases you do not have to configure imports and exports. So just leave them empty and check the Manifest in the jar. Only if it is not correct you have to manually configure. If you configure additional imports do not forget to add ,*. if you forget this then the automatically detected packages are not added and you have to specify all by hand which you typically do not want.
Upvotes: 1
Reputation: 11502
The maven bundle plugin uses bnd under the covers, which uses bytecode analysis to work out the imports retroactively from the compiled code. The package exports are more of a design thing, which is why they need to be explicitly specified.
You can look at the manifests being generated in your target folder, which I'd recommend to make sure you understand what's being done on your behalf.
Upvotes: 1