Search code examples
javaosgiapache-felix

How to troubleshooting Apache Felix not resolving an optional dependency?


I have an OSGi setup with Apache Felix and a large number of dependencies. One of these dependencies (Apache CXF) has an optional dependency on an package in Spring (org.springframework.context.support). This dependency does not get resolved (not listed in the "Imported Packages" in the Felix web UI). This causes a class not found exceptions in my app.

I think this is because I have a typical dependency hell problem; The spring bundle probably imports something, which imports something else which is irreconcilable with something (or maybe CXF itself) imports. Now if the dependencies are mandatory Felix displays a nice error overview how these dependency chains conflict but for optional dependencies it does not.

Is there a way I can get this information for optional dependencies?


Solution

  • As you suggest, Felix does not print an error message when an optional package import cannot be resolved, because there is no error... because it's optional.

    If you know the identity of the bundle that will provide the package, then install and start that bundle. This will force the error message that you want to see for diagnostics.

    By the way, it looks like you are dealing with a poorly designed bundle. If it has an optional import then it should not throw CNFEs for types in that package. That it does indicates the import should be mandatory, not optional.