【问题标题】:AWS SDK in OSGi causing "Unable to resolve/Missing requirement" errorsOSGi 中的 AWS 开发工具包导致“无法解决/缺少要求”错误
【发布时间】:2015-05-22 17:48:00
【问题描述】:

我在尝试设置 OSGi 程序同时使用适用于 Java 的 AWS 开发工具包时遇到了一个非常烦人的问题。我正在使用带有 Bndtools 的 Eclipse,并尽可能地创建了一个基本的项目。我所要做的就是导入 AWS 开发工具包的任何部分,然后我开始遇到一些我似乎无法解决的错误。

首先,我的测试类如下:

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.cmpn、osgi.core、org.apache.felix.dependencymanager 和com.amazonaws.aws-java-sdk-osgi。我从Maven Repository 获得的 AWS 开发工具包捆绑包也将该页面上指定的所有依赖项添加到本地存储库中。然后我创建了一个运行描述符,它在将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 中看到了一些内容,指出OSGi 环境中只包含java.* 包,因此即使jaxp 是Java 运行时库的一部分,我也必须专门导入它。因此,我查找了该库的 OSGi 包,并再次在 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 环境,但我不太确定在运行它时该怎么做从 Eclipse 通过 Bndtools,或者如果这样做甚至可以解决问题。

【问题讨论】:

    标签: java eclipse amazon-web-services osgi


    【解决方案1】:

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

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

    现在我的 OSGi 框架启动并在 OP 中运行 Test 类而没有错误!本来我只加了org.w3c.dom.html,但是这导致另外两个弹出错误,所以我加了。

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

    【讨论】:

    • 附带说明一下,我还删除了 jaxp 库的下载版本,并将 JRE 包添加到其中。
    猜你喜欢
    • 2017-03-24
    • 2012-02-26
    • 2019-05-29
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    • 2015-08-09
    • 2012-01-11
    • 1970-01-01
    相关资源
    最近更新 更多