在Karaf 2.4 / Felix 4.x中运行jackrabbit 2.11时出现OSGi错误

时间:2015-12-01 10:19:24

标签: osgi jcr

我试图使用JackRabbit 2.11.1连接到远程仓库(使用jackrabbit-jcr-rmi)。这些捆绑包在JBoss Fuse 6.2中运行,其中引用了Apache Karaf 2.4 / Felix 4.4。在启动时,我得到以下例外。 如果我尝试使用jackrabbit-bundle我得到 "缺少约束:Import-Package:com.ibm.db2.jcc;版本=" 0.0.0"" 所以我很困惑,JackRabbit 2.x OSGi准备好了吗?或者我需要使用Sling或Oak,还是......?

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]

另见https://issues.apache.org/jira/browse/JCR-3917

1 个答案:

答案 0 :(得分:1)

我用一个可怕的黑客解决了它。

  • 将我需要的依赖项嵌入到自己的jar中。
  • 将ContextClassLoader设置为提供类的类加载器(SPI首先应该做什么,但是没有用,可能是因为我需要包装比我更多的罐子?)。

所以,在maven-bundle-plugin中我做了:

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

在我的消费代码中:

ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(Jcr2davRepositoryFactory.class.getClassLoader());
//
repository = JcrUtils.getRepository(uri);
session = getSession();
// restore original classloader
Thread.currentThread().setContextClassLoader(originalContextClassLoader);