【发布时间】:2015-07-22 19:28:30
【问题描述】:
我正在尝试设置一个在内部运行在 OSGi 上的应用程序,并尝试使用教程 here,但我一直收到错误消息“方法 getBundleContext() 未针对类型框架定义”。据我所知,我使用的是正确的库,但在提到的文章中没有指定,所以我不是 100% 确定。我还尝试了 Apache 网站上的示例,here,这导致了同样的问题。代码如下:
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
public class Main {
public static void main(String[] args) throws BundleException {
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<String, String>();
Framework framework = frameworkFactory.newFramework(config);
framework.start();
// Throws error that it cannot find method getBundleContext()
BundleContext context = framework.getBundleContext();
List<Bundle> installedBundles = new LinkedList<Bundle>();
installedBundles.add(context.installBundle("file:org.apache.felix.shell-1.4.2.jar"));
installedBundles.add(context.installBundle("file:org.apache.felix.shell.tui-1.4.1.jar"));
for (Bundle bundle : installedBundles) {
bundle.start();
}
}
}
唯一有意义的是,要么我使用了错误的库,要么库已更改,而我尝试调用的方法在过去 4 年中已被弃用。有谁知道我该如何解决这个问题?
我怀疑它有什么不同,但如果有,我正在使用 Bndtools for Eclipse 来创建这个项目。
【问题讨论】:
标签: java frameworks osgi