Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional bundle dependency #76

Open
diamondarts opened this issue Oct 20, 2015 · 2 comments
Open

Add optional bundle dependency #76

diamondarts opened this issue Oct 20, 2015 · 2 comments
Labels
osgi Issues related to OSGi metadata of providers

Comments

@diamondarts
Copy link

Hello,

I am using bundle com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider in an OSGi environment. The first thing I got was this exception:

java.lang.ClassNotFoundException: com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector cannot be found by com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider_2.6.3
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:432)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:337)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.fasterxml.jackson.jaxrs.json.JsonMapperConfigurator._resolveIntrospector(JsonMapperConfigurator.java:109)

The bundle com.fasterxml.jackson.module.jackson-module-jaxb-annotations was active, but not visible by the class loader of the first bundle.

My workaround was a fragment bundle. However, my suggestion here is to make the first bundle depend optionally on the other:

Require-Bundle: com.fasterxml.jackson.module.jackson-module-jaxb-annotations;bundle-version="2.6.3";resolution:=optional

Thanks for the good work,
Björn

@cowtowncoder
Copy link
Member

This looks odd as pom.xml for json sub-module does contain:

<osgi.import>
...
,com.fasterxml.jackson.module.jaxb;resolution:=optional

which should, as far as I know, load the dependency dynamically if requested.
But I am guessing that's now how it works.

I am open to suggestions for solving this problem.

@mcculls
Copy link
Contributor

mcculls commented Jan 22, 2016

@diamondarts which order did you install/activate the two bundles? If the jackson-jaxrs-json-provider bundle was installed and resolved before the jackson-module-jaxb-annotations bundle then the optional import would be disabled (because in OSGi optional imports are only checked at the time the bundle is resolved, and if the package is not available at that time then it's not checked again until the bundle is refreshed/re-installed). So one option is to make sure the jackson-module-jaxb-annotations bundle is always resolved before the jackson-jaxrs-json-provider bundle (using a deployment manager or a container like Karaf can help). Alternatively if you can't change the install order you could refresh the jackson-jaxrs-json-provider bundle after the jackson-module-jaxb-annotations bundle was installed.

Another solution would be to use DynamicImport-Package instead of the optional import:

DynamicImport-Package: com.fasterxml.jackson.module.jaxb;version="[2.6,3)"

since dynamic imports are checked when needed, instead at bundle resolution time - and if a dynamic import isn't available then it will be rechecked the next time it's requested. (In other words it only caches a successful lookup, compared to an optional import which also caches a failed lookup). So a dynamic import would let you install the bundles in any order, at the cost of repeated failed lookups for the case when the jaxb bundle is not installed.

http://moi.vonos.net/java/osgi-classloaders/#optional-imports-and-dynamic-imports covers more of the pros and cons of optional vs dynamic imports

Hope this helps

@cowtowncoder cowtowncoder added the osgi Issues related to OSGi metadata of providers label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
osgi Issues related to OSGi metadata of providers
Projects
None yet
Development

No branches or pull requests

3 participants