Osgi PAX考试-未找到类错误

Osgi PAX考试-未找到类错误,osgi,apache-karaf,karaf,pax-exam,pax,Osgi,Apache Karaf,Karaf,Pax Exam,Pax,我正在为我们的项目进行PAX集成测试,在类加载方面我面临一些问题 我在PAX(用过的karaf容器)中部署了几个包。一旦karaf启动,我可以看到我的捆绑包和服务启动并处于活动状态。然而,在我的测试用例中,我引用了一个类(不是服务,也不是组件),它将在测试执行期间使用。该类位于bundle中,bundle已成功启动并运行,但在测试用例执行中访问该类时,我得到ClassnotFoundError,如下所示 **java.lang.ClassNotFoundException: com.myproj

我正在为我们的项目进行PAX集成测试,在类加载方面我面临一些问题

我在PAX(用过的karaf容器)中部署了几个包。一旦karaf启动,我可以看到我的捆绑包和服务启动并处于活动状态。然而,在我的测试用例中,我引用了一个类(不是服务,也不是组件),它将在测试执行期间使用。该类位于bundle中,bundle已成功启动并运行,但在测试用例执行中访问该类时,我得到
ClassnotFoundError
,如下所示

**java.lang.ClassNotFoundException: com.myproject.sample.bundle.DatabaseConfig
        at** org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at com.integrationtest.testcases.internal.development.LaunchContainerTest.populateDBProfiles(LaunchContainerTest.java:189)
        at com.integrationtest.testcases.internal.development.LaunchContainerTest.testLaunchOSGiContainerWithDefualtSettingsAndSleep(LaunchContainerTest.java:152)

这与容器有关吗?

因为测试本身也将在OSGi上下文中运行,所以需要调整测试。动态生成的测试包需要知道它需要导入有问题的类。 为此,可以添加专门的探测器配置方法。如下所示:

@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
    //make sure the needed imports are there. 
    probe.setHeader(Constants.IMPORT_PACKAGE, "*,com.myproject.sample.bundle.*");
    return probe;
}

测试中的代码是什么样子的?
@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
    //make sure the needed imports are there. 
    probe.setHeader(Constants.IMPORT_PACKAGE, "*,com.myproject.sample.bundle.*");
    return probe;
}