OSGi中的AWS SDK导致“无法解决/缺少需求”错误

时间:2015-05-22 17:48:00

标签: java eclipse amazon-web-services osgi

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

首先,我的测试类如下:

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中看到一些内容表明OSGi环境中只包含java.*个包,所以即使jaxp是Java运行时库的一部分,我也必须专门导入它。所以我查找了一个OSGi库,然后再次在Maven Repository中找到它,下载并将其添加到我的本地仓库中。这修复了解决错误,但是现在我在运行描述符中单击Run 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运行它,或者如果这样做甚至可以解决问题。

1 个答案:

答案 0 :(得分: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,但这导致其他2弹出错误,所以我添加了它们。

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