在Pax考试中加载ipojo Maven Bundle

时间:2013-02-20 00:20:08

标签: apache-felix pax-exam pax-runner ipojo

我正在尝试使用Pax Exam创建一个测试,其中我为测试加载的一些包依赖于包" org.apache.felix.ipojo &# 34。

如果我在Pax Exam配置中遗漏了一行加载此捆绑包,例如:

@Configuration
public Option[] config() throws MalformedURLException{
    return options(
            junitBundles(),
            BUNDLES OTHER THAN(org.apache.felix.ipojo),
            ...

然后我收到一个错误,指出此包是缺少的依赖项:

ERROR: Bundle com.N.A [35] Error starting mvn:com.N/com.N.A (org.osgi.framework.BundleException: Unresolved constraint in bundle com.N.A [35]: Unable to resolve 35.0: missing requirement [35.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.ipojo)(version>=1.8.0)))
org.osgi.framework.BundleException: Unresolved constraint in bundle com.N.A [35]: Unable to resolve 35.0: missing requirement [35.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.ipojo)(version>=1.8.0))
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3826)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1868)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191)
        at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)
        at java.lang.Thread.run(Thread.java:662)

但是,如果我添加一行包含它:

@Configuration
public Option[] config() throws MalformedURLException{
    return options(
            junitBundles(),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo")
            ...

我收到一条消息,指出ClassCastException,我认为这是由于ipojo包被内置到Felix中。

ERROR: Bundle org.apache.felix.ipojo [34] Error starting mvn:org.apache.felix/org.apache.felix.ipojo (org.osgi.framework.BundleException: Activator start error in bundle org.apache.felix.ipojo [34].)
java.lang.ClassCastException: org.apache.felix.ipojo.Extender cannot be cast to org.osgi.framework.BundleActivator
        at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4177)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1972)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1895)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191)
        at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)
        at java.lang.Thread.run(Thread.java:662)

我使用Felix和JUint4TestRunner作为跑步者。

如何在没有冲突的情况下访问此依赖项?

2 个答案:

答案 0 :(得分:1)

ClassCastException最有可能表示您在类路径上有另一份OSGi API副本。如果您对org.osgi:org.osgi.core拥有Maven依赖关系,请确保范围为provided而不是compiletest

答案 1 :(得分:0)

这是我使用的:

public CompositeOption ipojoBundles() {
    return new DefaultCompositeOption(
            mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
            mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
}

使用以下版本:iPOJO 1.8.6和osgi-helpers 0.6.0

帮助程序是减少编写OSGi测试时的负担的方法。

相关问题