简体   繁体   English

来自OSGi捆绑包的相对路径

[英]Relative path from an OSGi bundle

I have a updater bundle that lookups in a specific folder "bundle" and checks for new bundles to install and updates for currently installed bundles. 我有一个更新程序包,它在特定的文件夹“ bundle”中查找并检查要安装的新包,并检查当前安装的包。 Inside a parent directory, OSGi framework is in the "/framework" directory, updater bundle is in the "/system" directory and the directory needs to be checked is the "/bundles" directory in the same parent directory. 在父目录中,OSGi框架位于“ / framework”目录中,更新程序包位于“ / system”目录中,需要检查的目录是同一父目录中的“ / bundles”目录。 Inside the updater bundle, a File object with a relative path is created but it's not working with the "./bundles" string, and i dont know which jar file the path is supposed to be relative with. 在更新程序包中,创建了一个具有相对路径的File对象,但它不适用于“ ./bundles”字符串,而且我不知道该路径应该与哪个jar文件相对。 I would appreciate any insight or information about this problem.. Thanks, Deniz 我将不胜感激或有任何有关此问题的信息。

Edit: Already figured out. 编辑:已经想通了。 Looks like path is resolved according to the Ruby script i use to start Equinox. 看起来路径是根据我用来启动Equinox的Ruby脚本解析的。 So resolution path is a directory i start Equinox by passing it a "-console" flag using Ruby system. 因此,解析路径是一个目录,我通过使用Ruby系统向其传递“ -console”标志来启动Equinox。 Thanks for answers, Deniz 感谢您的回答,德尼兹

Doing new File("./bundles") resolves against the current working directory. 执行新的File(“ ./ bundles”)会针对当前工作目录进行解析

You can install your bundle by getting an input stream yourself and calling BundleContext#installBundle(String, InputStream). 您可以自己获取输入流并调用BundleContext#installBundle(String,InputStream)来安装软件包。

OSGi itself makes no assumptions about filesystem layout, or that bundles are even on disk. OSGi本身不对文件系统布局做任何假设,甚至不认为捆绑包在磁盘上。 But if you are using Equinox as your framework you can resolve your relative paths against the "osgi.install.area". 但是,如果您使用Equinox作为框架,则可以针对“ osgi.install.area”解析相对路径。 The Location service can give you this. 定位服务可以为您提供此服务 And then use the absolute path to install the bundle. 然后使用绝对路径安装捆绑软件。

Or, you can get the System Bundle (BundleContext.getBundle(0)), and use FileLocator (from org.eclipse.equinox.common) to find it on disk. 或者,您可以获得系统捆绑包(BundleContext.getBundle(0)),然后使用FileLocator(来自org.eclipse.equinox.common)在磁盘上找到它。

Depends on your OSGi configuration and implementation. 取决于您的OSGi配置和实施。 It could be relative to a number of places, the most likely one being the framework location. 它可能与许多地方有关,最有可能是框架位置。 Why don't you test by creating your File with a relative path, and the checking the value of 为什么不通过创建具有相对路径的File并检查的值来进行测试

new File("./bundles").getAbsolutePath();

Hope this helps. 希望这可以帮助。

Already figured out. 已经想通了。 Looks like path is resolved according to the Ruby script i use to start Equinox. 看起来路径是根据我用来启动Equinox的Ruby脚本解析的。 So resolution path is a directory i start Equinox by passing it a "-console" flag using Ruby system. 因此,解析路径是一个目录,我通过使用Ruby系统向其传递“ -console”标志来启动Equinox。 Thanks for answers, Deniz 感谢您的回答,德尼兹

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

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