【发布时间】:2023-03-03 00:22:01
【问题描述】:
目前我正在使用 Jetty 和 Equinox 开发基于 OSGi 的 WebApp(请参阅:http://wiki.eclipse.org/Jetty/Tutorial/EclipseRT-Jetty-Starter-Kit)。 到目前为止一切都很好,但我无法访问我自己的包的某些文件/资源。 位置/路径是“configuration/data/config.csv”和“configuration/data/data.zip”。 我已经测试了一切:
context.getBundleContext().getBundle().getEntry("config.csv");
context.getBundleContext().getBundle().getResource("config.csv");
this.getClass().getClassLoader().getResource("config.csv");
context.getBundleContext().getDataFile("config.csv");
当然还有所有可能的路径变体,例如:“configuration/data/config.csv”、“/configuration/data/config.csv”、“\configuration/data/config.csv”、“/config.csv” . 此外,我已将文件夹添加到 OSGi 类路径(在 MANIFEST.MF 中):
Bundle-ClassPath: .,
configuration/data/
生成的 URL 看起来总是像这样(或 null):“configuration/CBR-Data/config.csv”,当我将它传输到文件对象“D:\configuration\CBR-Data\config.csv”时.
但我真正不明白的是,我的一个 DS 的属性文件已完美加载:<properties entry="configuration/dsconfig.properties"/>
有人有想法/提示或其他什么吗?我快疯了……
【问题讨论】:
-
您能否发布代码,获取资源的 URL 以及之后您如何使用它。当您使用 getEntry() 时,您应该将“configuration/data/config.csv”作为参数传递给 getEntry()。生成的 URL 将具有以下格式:bundleentry://20.fwk1235/resource.txt。它似乎不可能具有您发布的格式。所以,有一些事情发生了,你的问题并不清楚。
-
你说得对,对不起。
URL configURL = context.getBundleContext().getBundle().getEntry("configuration/data/confid.csv");的输出是“bundleentry://6.fwk33311724/configuration/data/config.csv”。我尝试通过:File configFile = new File(configURL.getPath());将 URL 转换为文件。路径输出configFile.getAbsolutePath();比:“D:\configuration\data\config.csv”
标签: file resources osgi bundle