使用osgi访问包内的公共属性文件 [英] access common property file inside bundle with osgi

查看:92
本文介绍了使用osgi访问包内的公共属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个捆绑包的osgi应用程序(在felix中).一个捆绑包中有一些公共属性文件,而其余捆绑包只需要使用它们即可.

I have an osgi application (in felix) with multiple bundles. There are some common property files in one bundle and the rest of the bundles need just use them.

我们使用maven和spring osgi,属性文件如下所示:

We use maven and spring osgi, the property files are in resouces like:

<path to bundle>/src/main/resources/
    common.properties
    engine.properties
    ...

Maven通常在捆绑罐中构建它们,因此它们应该位于应用程序类路径中,但是Spring无法访问它们,这将失败:

Maven builds them inside the bundle jar normally so they should be in an application classpath, but Spring has no access to them, this fails:

<context:property-placeholder location="classpath:common.properties" />

(尝试使用classpath *:和其他组合)

(tried classpath*: and other combinations)

我已阅读这真的与osgi意识形态有关,是否存在一些全球性问题,没有使它起作用的标准方法?只有那样的黑客和变通办法<osgix:cmProperties...>?

Is it really some global issue with osgi ideology and no standard way to get it working? Only hacks and workarounds like that or <osgix:cmProperties...>?

它令人担忧,因为它使部署更加困难且容易出错:您不能像普通应用程序一样仅在mvn deploy内将属性文件部署在jar中,-您必须手动将它们复制到每个发行版的生产环境中

It concerns because it makes deployment harder and error-prone: you can't deploy property files inside jars with just mvn deploy as in normal application, - you'll have to manually copy them to the production box on each release.

推荐答案

对于OSGi,没有通用的应用程序类路径.尽管这些属性位于包含它们的捆绑软件的类路径中,但是它们不一定位于使用它们的捆绑软件的类路径中.

With OSGi, there isn't a universal application classpath. Although the properties are on the classpath of the bundle which contains them, they're not necessarily on the classpath of the bundles using them.

这有点难看,但是通常导出包含属性文件夹的包"将使它们可访问.在这种情况下,看起来像是.",这很丑陋,但是您可以将它们放在"properties"目录中(例如),然后导出属性包.使用这些属性的捆绑包还需要导入属性包.

It's a little bit ugly, but in general exporting the 'package' containing the property folders will make them accessible. In this case it looks like that would be '.', which is very ugly, but you could put them in a 'properties' directory (say), and then export a properties package. Bundles which use those properties would also need to import the properties package.

或者,使用包含包的类加载器查找资源也可以,尽管我无法评论其Spring配置是什么样.

Alternatively, using the containing bundle's classloader to look up the resource will work, although I can't comment on what the Spring config for that would look like.

这篇关于使用osgi访问包内的公共属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆