- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 pax-exam 加载、激活和访问 osgi 包。
以下源代码是我的 pax-exam 测试,它使用 native 容器使用 pax-exam 2.3 运行。
package fr.xlim.ssd.vtg.osgi;
import java.net.URISyntaxException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.ExamReactorStrategy;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertNotNull;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.options;
@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public class BasicOSGILoaderTest {
private Logger logger = LoggerFactory.getLogger(BasicOSGILoaderTest.class);
@Inject
private BundleContext bundleContext;
@Configuration
public Option[] config() {
String projectRoot = null;
try {
projectRoot = ClassLoader.getSystemResource(".").toURI().toURL().toString();
projectRoot = projectRoot.toString().substring(0,projectRoot.toString().length() - 27);
logger.debug("project root: {}", projectRoot);
} catch (MalformedURLException e) {
logger.error("malformed URL to project root: {}", projectRoot, e);
throw new IllegalStateException(e);
} catch (URISyntaxException e) {
logger.error("URI Syntax Error to project root: {}", projectRoot, e);
throw new IllegalStateException(e);
}
return options(
junitBundles(),
logProfile(),
bundle(projectRoot + "libs/org.eclipse.ant.core_3.2.300.v20110511.jar"),
bundle(projectRoot + "libs/org.eclipse.core.contenttype_3.4.100.v20110423-0524.jar"),
bundle(projectRoot + "libs/org.eclipse.core.expressions_3.4.300.v20110228.jar"),
bundle(projectRoot + "libs/org.eclipse.core.jobs_3.5.100.v20110404.jar"),
bundle(projectRoot + "libs/org.eclipse.core.resources_3.7.100.v20110510-0712.jar"),
bundle(projectRoot + "libs/org.eclipse.core.runtime_3.7.0.v20110110.jar"),
bundle(projectRoot + "libs/org.eclipse.equinox.app_1.3.100.v20110321.jar"),
bundle(projectRoot + "libs/org.eclipse.equinox.common_3.6.0.v20110523.jar"),
bundle(projectRoot + "libs/org.eclipse.equinox.preferences_3.4.1.R37x_v20110725.jar"),
bundle(projectRoot + "libs/org.eclipse.equinox.registry_3.5.101.R37x_v20110810-1611.jar"),
bundle(projectRoot + "libs/org.eventb.core_2.4.0.r14093.jar"),
bundle(projectRoot + "libs/org.eventb.core.ast_2.4.0.r14093.jar"),
bundle(projectRoot + "libs/org.eventb.core.seqprover_2.4.0.r14093.jar"),
bundle(projectRoot + "libs/org.rodinp.core_1.5.0.r14093.jar"),
equinox().version("3.7.1")
);
}
@Test
public void checkBundleContext1() {
assertNotNull(bundleContext);
}
@Test
public void checkBundleContext2(BundleContext bc) {
assertNotNull(bc);
}
@Test
public void checkAccessToRodinDB() {
RodinCore.getRodinDB();
}
}
但是我有以下问题:
两个 checkBundleContext 方法都失败,注入(inject)的包上下文(使用 @Inject
)或作为测试方法的参数传递始终为 null
从 org.rodinp.core_1.5.0.r14093.jar
类 RodinCore
中访问静态方法 getRodinDb()
> 抛出一个关于 org.rodinp.core.RodinCore
的 ClassNotFoundException
,即使包 org.rodinp.core
在 Export-package 中捆绑。
最佳答案
检查您的导入。使用
import javax.inject.Inject;
Injection is indicated by a javax.inject.Inject annotation. Pax Exam's own Inject annotation of the 1.x release line is now deprecated.
关于java - BundleContext 在使用 pax-exam 的单元测试中为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9837474/
我最近开始使用 OSGi 框架。我正在尝试从 Java 主应用程序启动 OSGi 框架。我正在关注这个tutorial将 OSGI 容器嵌入到我的项目中。 下面是我的 Java 主应用程序,我用它来启
有人能说 BundleContext.installBundle 是否是线程安全的吗?我已阅读文档,但找不到。 最佳答案 The documentation明确指出 BundleContext 是线程
我是 Spring DM 的新成员,我想访问 Bundlecontext。我的问题是我有一个 Activator 捆绑包,但它没有 xml 配置文件。我无法触摸这个包,然后我需要访问 BundleCo
以我对 OSGi 的熟练程度,我可以从以下位置获取属性字符串: BundleContext.getProperty(key)(存储在'conf/config.properties') Componen
我编写了一个测试,其中运行一个需要加载 osgi 服务的类。当我开始测试时,每次都会收到 NullPointerException。运行应用程序时它工作正常。我的捆绑上下文为空。我该如何解决这个问题?
我按照本教程将 OSGi 嵌入到我的基于 Maven 的应用程序中。我有一个类文件,用于创建并启动如上所述的框架 here它在那里工作得很好,因为我可以轻松获取 BundleContext。 我已在
我有一个包含多个组件的 OSGi 包,我想激活/停用同一包中其他组件的组件。 我从下面的代码中得到了 BundleContext: import aQute.bnd.annotation.compon
如何在 bean 定义 xml 中传递对 BundleContext 的引用? 最佳答案 你可以这样做: 关于java - 如何在 SpringDM 中将 bundleContext 引用传
我正在使用 pax-exam 加载、激活和访问 osgi 包。 以下源代码是我的 pax-exam 测试,它使用 native 容器使用 pax-exam 2.3 运行。 package fr.xli
我刚刚开始使用 Eclipse RCP 应用程序,它基本上只是提供的“hello world”示例之一。 当应用程序启动时,我想查看我的命令行参数并根据它们启动一些服务。我可以在 IApplicati
我正在尝试以 Java 配置方式在 Spring 中配置 Apache Camel,详见 example .然而,我被困在依赖步骤,因为 BundleContextAware 和(传递地)Bundle
我是 OSGi 新手,在尝试运行此库的示例时遇到问题:https://github.com/jitsi/libjitsi java.lang.NoClassDefFoundError: org/osg
我是一名优秀的程序员,十分优秀!