问题
Hi I am new to ServiceMix, so probably I am asking same question which might be answered but I couldn't figure out.
My doubt is how do I manage compile time vs runtime dependencies when using bundle in ServiceMix OSGI. That is if I am building a .jar workable(by unit tests aleast) artifact with maven where all compile time dependencies say example(camel,spring) are handled by pom.xml dependencies and are loaded into jar as needed libs for successful build. So when I am deploying the jar in OSGI those libs(camel,spring) are already existing in maven generated jar. Now as OSGI bundles I am supporting same bundles(camel,spring) here during runtime from container.
So I am confused how or which copy of required dependency bundle my code picks for execution. Is it the one within .jar or the one provided by OSGI container. Though I am aware the MANIFEST file provides options, like Import Packages which help to import the dependencies from other OSGI bundles in container
May be I am missing some very key points of using OSGI here, so please correct me if I am wrong on any assumptions and provide some pointers/suggestions
Thanks
回答1:
Looks like you're using the maven-bundle-plugin to generate your own bundle. In that case just make sure your dependencies for camel, etc. are of provided-scope instead of compile-scope
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<scope>provided</scope>
</dependency>
This will make sure your bundle only contains the dependencies it needs.
回答2:
It all depends on how your manifest looks like:
- You don't import the package (either with Import-Package, Require-Bundle or Dynamic-Import-Package): all classes are only loaded from your bundles classpath
- You import the package with the optional flag: If the package is available it will be taken from the OSGi framework otherwise it will search your bundle classpath
- You import the package with Dynamic-Import-Package: The framework will search your bundle and then other bundles exporting the package
So normally you choose to import package all dependencies but you can also embedd them into your jar, it all depends on your use-case.
来源:https://stackoverflow.com/questions/25718033/dependency-management-in-osgi-bundle-servicemix