简体   繁体   English

如何确保在主机捆绑包之前安装我的OSGi片段?

[英]How do I ensure my OSGi fragments get installed before the host bundle?

I am trying to deploy guice into JBoss AS7 (7.2.0-Alpha). 我正在尝试将guice部署到JBoss AS7(7.2.0-Alpha)中。 This comes as a number of jars. 这是一些罐子。 The ones I am interested in are 我感兴趣的是

  • guice 吉斯
  • guice-servlet 吉斯-的servlet
  • guice-persist 吉斯 - 坚持

guice is the a host bundle and guice-servlet and guice-persist are fragments of this host. guice是一个主机包,guice-servlet和guice-persist是这个主机的片段。

When I start the container the host bundle always gets installed, resolved and becomes active. 当我启动容器时,主机包总是被安装,解析并变为活动状态。 The fragments always get installed and sometimes get resolved and "included" in the host bundle and sometimes don't. 片段总是被安装,有时会被解析并“包含”在主机包中,有时则不会。 This seems to be random. 这似乎是随机的。

I have also tried Eclipse Virgo and the behaviour is the same, but, it has the ability to define plans whereby you can circumvent this problem by defining the installation order. 我也尝试了Eclipse Virgo并且行为是相同的,但是,它能够定义计划,通过定义安装顺序可以绕过这个问题。 (I seemed to be able to make it work anyway). (无论如何,我似乎能够使它工作)。

Looking at the OSGi spec and reading the answer to this question it seems like this is the expected behaviour. 看看OSGi规范并阅读这个问题的答案,似乎这是预期的行为。 JBoss is an OSGi 4.2 container so the the Require-Capability and Provide-Capability headers aren't an option - plus I don't really want to modify jars which aren't mine. JBoss是一个OSGi 4.2容器,因此Require-CapabilityProvide-Capability标头不是一个选项 - 而且我真的不想修改不属于我的jar。

How am I supposed to get my host/fragment bundles to install and resolve reliably? 我怎么能让我的主机/片段包安装和可靠地解决?

One idea I have had (which I am reluctant to do as it doesn't seem right) is to use maven-bundle-plugin/bndtools and merge the guice bundles together into a single super-guice-bundle - effectively doing at build time what the container is failing to do for me at runtme. 我有一个想法(我不愿意做,因为它看起来不对)是使用maven-bundle-plugin / bndtools并将guice bundle合并到一个super-guice-bundle中 - 在构建时有效地做容器在runtme没有为我做什么。

As I said in my answer to the question you linked to: the fragment will be attached to the host if it is installed before the host resolves. 正如我在回答您链接到的问题时所述:如果在主机解析之前安装了片段,则片段将附加到主机。 The easiest way to achieve this is to install all bundles (including fragments) first, before allowing any of them to resolve. 实现此目的的最简单方法是首先安装所有捆绑包(包括碎片),然后再允许其中任何捆绑包解析。

In many cases the resolve is triggered by trying to start a bundle. 在许多情况下,尝试启动捆绑包会触发解决方案。 One of the most common errors people make in OSGi is trying to start each bundle immediately after it is installed. 人们在OSGi中犯的最常见错误之一就是在安装后立即尝试启动每个捆绑包。 You must not do this, ie you should not start any bundle until after you have installed all bundles that you intend to run. 您不能这样做,即在安装要运行的所有软件包后才能启动任何软件包。

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

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