Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSGi errors when running jackrabbit 2.11 in Karaf 2.4 / Felix 4.x

Tags:

osgi

jcr

I'm trying to use JackRabbit 2.11.1 to connect to a remote repo (using jackrabbit-jcr-rmi). The bundles run in JBoss Fuse 6.2, which has Apache Karaf 2.4 / Felix 4.4 under the hood. On startup i get the exception below. If i try to use jackrabbit-bundle i get "Missing Constraint: Import-Package: com.ibm.db2.jcc; version="0.0.0"" So i'm confused, is JackRabbit 2.x OSGi ready? or do i need to use Sling or Oak , or .... ?

Caused by: org.osgi.framework.BundleException: Uses constraint violation. Unable to resolve bundle revision wrap_mvn_org.apache.jackrabbit_jackrabbit-core_2.11.1 [270.0] because it exports package 'org.apache.jackrabbit.core.config' and is also exposed to it from bundle revision org.apache.jackrabbit.jackrabbit-data [276.0] via the following dependency chain:
wrap_mvn_org.apache.jackrabbit_jackrabbit-core_2.11.1 [270.0]
import: (osgi.wiring.package=org.apache.jackrabbit.core.data.db)
export: osgi.wiring.package=org.apache.jackrabbit.core.data.db; uses:=org.apache.jackrabbit.core.config
export: osgi.wiring.package=org.apache.jackrabbit.core.config
org.apache.jackrabbit.jackrabbit-data [276.0]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4006)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2045)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:963)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.karaf.features.internal.FeaturesServiceImpl.doInstallFeatures(FeaturesServiceImpl.java:546)[9:org.apache.karaf.features.core:2.4.0.redhat-620133]

See also https://issues.apache.org/jira/browse/JCR-3917

like image 592
rwijngaa Avatar asked Nov 10 '22 00:11

rwijngaa


1 Answers

I solved it with a horrible hack.

  • Embed the dependencies i need into my own jar.
  • Set the ContextClassLoader to the classloader of the providing class (what the SPI thing was supposed to do in the first place but did not work, probably because i needed to wrap more jars than the one i did ?).

So, in the maven-bundle-plugin i did:

<Embed-Dependency>jackrabbit-jcr2dav*,jackrabbit-jcr2spi*,jackrabbit-jcr-commons*;scope=compile;inline=false</Embed-Dependency>

And in my consuming code:

ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(Jcr2davRepositoryFactory.class.getClassLoader());
//
repository = JcrUtils.getRepository(uri);
session = getSession();
// restore original classloader
Thread.currentThread().setContextClassLoader(originalContextClassLoader);
like image 110
rwijngaa Avatar answered Jan 04 '23 03:01

rwijngaa