OSGi 中的 AWS SDK 导致 "Unable to resolve/Missing requirement" 错误

AWS SDK in OSGi causing "Unable to resolve/Missing requirement" errors

我 运行 在尝试设置 OSGi 程序时遇到了一个非常烦人的问题,同时还使用了 Java 的 AWS SDK。我将 Eclipse 与 Bndtools 一起使用,并尽可能地创建了一个项目的基础。我所要做的就是导入 AWS SDK 的任何部分,然后我开始收到一些我似乎无法解决的错误。

首先,我的测试class如下:

package com.test;

import org.apache.felix.dm.DependencyActivatorBase;
import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.BundleContext;

import com.amazonaws.auth.BasicAWSCredentials;

public class Test extends DependencyActivatorBase {
    BasicAWSCredentials creds;
    public Test() {

    }
    @Override
    public void init(BundleContext arg0, DependencyManager arg1) throws Exception {
        arg1.add(createComponent().setInterface(Object.class.getName(), null).setImplementation(Test.class));
    }
}

然后我创建一个 Bundle 描述符并将 com.test 添加到私有包部分。在 bnd.bnd 下,我在构建路径中有 osgi.cmpnosgi.coreorg.apache.felix.dependencymanagercom.amazonaws.aws-java-sdk-osgi。我从 Maven Repository 获得的 AWS SDK 包并将该页面上指定的所有依赖项也添加到本地存储库。然后,我创建了一个 运行 描述符,在将 myTest.testbundle 添加到 运行 要求后尝试解决时,它立即给出以下错误:

Unable to resolve <<INITIAL>> version=null:
   missing requirement Require[osgi.identity]{}{filter=(osgi.identity=myTest.testbundle)} [caused by:
   Unable to resolve myTest.testbundle version=0.0.0:
   missing requirement Require[osgi.wiring.package]{}{filter=(&(osgi.wiring.package=com.amazonaws.auth)(version>=1.9.0)(!(version>=2.0.0)))} [caused by:
   Unable to resolve com.amazonaws.aws-java-sdk-osgi version=1.9.36:
   missing requirement Require[osgi.wiring.package]{}{filter=(osgi.wiring.package=com.sun.org.apache.xerces.internal.jaxp)}]]

我又在 another post that stated that only java.* packages are included in the OSGi environment, so even though jaxp is part of the Java runtime library, I would have to specifically import it. So I looked for an OSGi bundle of the library and found it in the Maven Repository 看到了一些东西,下载并添加到我的本地仓库中。这修复了解析错误,但现在当我在 运行 描述符中单击 运行 OSGi 时出现以下错误:

! could not resolve the bundles: [com.amazonaws.aws-java-sdk-osgi-1.9.36Unresolved constraint in bundle com.amazonaws.aws-java-sdk-osgi [1]: Unable to resolve 1.0: missing requirement [1.0] osgi.wiring.package; (osgi.wiring.package=com.sun.org.apache.xerces.internal.jaxp) [caused by: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)]
, myTest.testbundle-0.0.0Unresolved constraint in bundle myTest.testbundle [7]: Unable to resolve 7.0: missing requirement [7.0] osgi.wiring.package; (&(osgi.wiring.package=com.amazonaws.auth)(version>=1.9.0)(!(version>=2.0.0))) [caused by: Unable to resolve 1.0: missing requirement [1.0] osgi.wiring.package; (osgi.wiring.package=com.sun.org.apache.xerces.internal.jaxp) [caused by: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)]]
, org.apache.servicemix.bundles.jaxp-ri-1.4.5.1Unresolved constraint in bundle org.apache.servicemix.bundles.jaxp-ri [16]: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)
]
! Failed to start bundle com.amazonaws.aws-java-sdk-osgi-1.9.36, exception Unresolved constraint in bundle com.amazonaws.aws-java-sdk-osgi [1]: Unable to resolve 1.0: missing requirement [1.0] osgi.wiring.package; (osgi.wiring.package=com.sun.org.apache.xerces.internal.jaxp) [caused by: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)]
! Failed to start bundle myTest.testbundle-0.0.0, exception Unresolved constraint in bundle myTest.testbundle [7]: Unable to resolve 7.0: missing requirement [7.0] osgi.wiring.package; (&(osgi.wiring.package=com.amazonaws.auth)(version>=1.9.0)(!(version>=2.0.0))) [caused by: Unable to resolve 1.0: missing requirement [1.0] osgi.wiring.package; (osgi.wiring.package=com.sun.org.apache.xerces.internal.jaxp) [caused by: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)]]
! Failed to start bundle org.apache.servicemix.bundles.jaxp-ri-1.4.5.1, exception Unresolved constraint in bundle org.apache.servicemix.bundles.jaxp-ri [16]: Unable to resolve 16.0: missing requirement [16.0] osgi.wiring.package; (osgi.wiring.package=org.w3c.dom.html)

如果我在测试代码中注释掉引用 AWS 组件的行,错误就会消失。我正竭尽全力想弄清楚我需要做什么来解决这个问题。我使用的 运行 描述符是使用默认设置创建的,因此它在 org.apache.felix.framework;version='[4,5)' 上 运行,但我在 JavaSE 下将其更改为 运行 -1.8 环境而不是 1.7.

查看问题和其他一些与之相关的帖子,看来我需要明确告诉它将 org.w3c.dom 库导入 OSGi 环境,但我不太确定该怎么做当 运行通过 Bndtools 从 Eclipse 中连接它时,或者如果这样做甚至可以解决问题。

我终于想出了如何添加缺少的 JRE 包。在 Bndtools Run Descriptor 中,我点击了 Source 并添加了以下内容:

-runsystempackages:  \
    org.w3c.dom.html,\org.w3c.dom.ranges,\org.w3c.dom.traversal

现在我的 OSGi 框架启动并在 OP 中运行 Test class 没有错误!我最初只添加了 org.w3c.dom.html,但这导致其他 2 个弹出错误,所以我添加了它们。

注意:您需要停止并重新启动框架才能使此更改生效。