我想在OSGi容器中安装OSGi包。我在我的一个文件夹中有一个jar文件..我将这个jar文件读入ByteArray
,然后我使用这个ByteArray
在OSGi容器中安装Framework
包。下面是代码..使用ByteArray安装OSGi包
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
framework = frameworkFactory.newFramework(new HashMap<String, String>());
framework.start();
final String basePath = "C:\\LocalStorage";
final BundleContext bundleContext = framework.getBundleContext();
final List<Bundle> installedBundles = new LinkedList<Bundle>();
String filename = "Framework" + "-" + "1.0.0" + ".jar";
String localFilename = basePath+ File.separatorChar + filename;
File file = new File(localFilename);
byte [] fileData = new byte[(int)file.length()];
DataInputStream dis = new DataInputStream((new FileInputStream(file)));
dis.readFully(fileData);
dis.close();
// But below line gives me exception always-
installedBundles.add(bundleContext.installBundle(filename, new ByteArrayInputStream(fileData)));
for (Bundle bundle : installedBundles) {
bundle.start();
}
下面是个例外,我总是GET-
org.osgi.framework.BundleException: Bundle symbolic name and version are not unique: Framework:1.0.0
谁能告诉我,我做错了什么?而我需要的,因为在我的一些在另一个类的代码,我使用的ByteArray使用的ByteArray,所以我需要通过罐的ByteArray的文件,以这些方法..
更新: -
但如果我像这样安装它,那么它工作正常。它不工作,如果我通过的ByteArray安装它..
final String basePath = "C:\\LocalStorage";
final BundleContext bundleContext = framework.getBundleContext();
final List<Bundle> installedBundles = new LinkedList<Bundle>();
String filename = "Framework" + "-" + "1.0.0" + ".jar";
String localFilename = Constants.FILE_PROTOCOL + basePath+ File.separatorChar + filename;
installedBundles.add(bundleContext.installBundle(localFilename));
for (Bundle bundle : installedBundles) {
bundle.start();
}
也许是可能的,我做错了什么与ByteArray的事情吗?任何想法?
我已经有这些条目在我的'MANIFEST.MF file' - '捆绑-ManifestVersion:2 捆绑-名称:框架 捆绑-SymbolicName:框架 捆绑-版本:1.0.0' – AKIWEB