简体   繁体   English

获取OSGi运行时中已安装的包的InputStream?

[英]Get InputStream of bundle already installed in OSGi runtime?

I am trying to create a backup file of a bundle that is installed in the runtime, so that I can uninstall it and then possibly reinstall from the backup if I want. 我正在尝试创建在运行时中安装的捆绑软件的备份文件,以便可以卸载它,然后根据需要从备份中重新安装。 Does anybody know how to get a handle on the location of the bundle file that is already installed in the runtime? 有人知道如何获取运行时中已安装的捆绑文件的位置吗? I would like to do this in a way that will work regardless of OSGi container (specifically, I want it to work in Equinox and Felix). 我想以一种与OSGi容器无关的方式来执行此操作(特别是,我希望它在Equinox和Felix中都能工作)。 Ideally this would be information gained from the Bundle object (or from information from an object acquired from the Bundle object). 理想地,这将是从获得的信息Bundle对象(或从从所获取的对象的信息Bundle对象)。

Edit: In a nutshell, I am getting every bundle installed ( bundleContext.getBundles ) and from that attempting to determine file paths of the bundles. 编辑:简而言之,我正在安装每个捆绑软件( bundleContext.getBundles ),并从中尝试确定捆绑软件的文件路径。

You can't do this. 你做不到 The OSGi spec does not provide any way to get the input stream for an installed bundle. OSGi规范不提供任何获取已安装包的输入流的方法。 This is mostly because the OSGi does not require that bundles come in the form of a JAR nor that they be stored in any archive format. 这主要是因为OSGi不需要捆绑软件以JAR的形式出现,也不需要以任何存档格式存储它们。 For example, an OSGi framework could store the entries of a bundle in a database and then look up requested classes and resources from that database. 例如,OSGi框架可以将束的条目存储在数据库中,然后从该数据库中查找请求的类和资源。 So you see there is no guarantee the bundles exist in JAR form after installation. 因此,您无法确保安装后捆绑软件以JAR形式存在。

Use bundle.getLocation(). 使用bundle.getLocation()。 It will return the location the bundle was installed from (if available). 它将返回捆绑软件的安装位置(如果有)。 There is no guarantee that you can load the bundle jar from there but depending on how you originally installed the bundle this works. 无法保证您可以从那里加载捆绑包,但取决于最初安装捆绑包的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM