简体   繁体   English

OSGi如何安装两个相同的捆绑包?

[英]OSGi how to install two identical bundle?

I want to install two identical bundle or the same bundle twice in OSGi container. 我想在OSGi容器中两次安装两个相同的捆绑软件或同一捆绑软件。 The OSGi container I am using is FUSE ESB. 我正在使用的OSGi容器是FUSE ESB。 Here is the bundle information: 这是捆绑包信息:

pom.xml: pom.xml中:

<groupId>com.helloworldbundle</groupId>
<artifactId>HelloWorldBundle</artifactId>
<version>1.0.0-SNAPSHOT</version>

blueprint: 蓝图:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

  <bean id="helloworldbundlecopybean"
    class="com.helloworldbundle.HelloWorld"
    init-method="init" destroy-method="destroy">
  </bean>

</blueprint>

The first installation is successful. 首次安装成功。 When I try to install it again, it failed. 当我尝试再次安装它时,它失败了。 Then I make a copy of the project and modify it: 然后,我复制该项目并对其进行修改:

change project folder name to HelloWorldBundleCopy 将项目文件夹名称更改为HelloWorldBundleCopy

change the artifact to 将工件更改为

<artifactId>HelloWorldBundleCopy</artifactId>

change bean id to 更改bean ID为

<bean id="helloworldbundlecopybeancopy"

But still I cannot install the modified bundle: 但是我仍然无法安装修改后的捆绑包:

Error executing command: Error installing bundles:
Unable to install bundle /home/li/Documents/Java/HelloWorldBundleCopy/target/HelloWorldBundleCpoy-1.0.0-SNAPSHOT.jar

update to my question: 更新我的问题:

Here is my scenario: 这是我的情况:

I have three hosts: Host1, Host2 and Host3 我有三个主机:Host1,Host2和Host3

FUSE ESB OSGi container is installed in Host3. FUSE ESB OSGi容器已安装在Host3中。 I need to run a service, for example HelloWorld on both Host1 and Host2. 我需要在Host1和Host2上都运行服务,例如HelloWorld。 And this service is registered with FUSE ESB which is on Host3. 并且此服务已在Host3上的FUSE ESB中注册。

That is why I need to register the same bundle twice with FUSE ESB. 这就是为什么我需要在FUSE ESB中两次注册相同的捆绑软件。

Here is my question: 这是我的问题:

  1. Is it possible to run a bundle outside the container, like running HelloWorld bundle on one host but register it to FUSE ESB on a different host? 是否可以在容器外部运行捆绑软件,例如在一台主机上运行HelloWorld捆绑软件但将其注册到另一台主机上的FUSE ESB? And how to do it? 以及如何做? The experiment I have done before is to register a service bundle to FUSE ESB on the same machine by: 我之前做过的实验是通过以下方法在同一台计算机上将服务包注册到FUSE ESB:

    FuseESB:karaf@root> install file:/home/li/Documents/Java/HelloWorldBundle/target/HelloWorldBundle-1.0.0-SNAPSHOT.jar FuseESB:karaf @ root>安装文件:/home/li/Documents/Java/HelloWorldBundle/target/HelloWorldBundle-1.0.0-SNAPSHOT.jar

2.How to modify the existing maven project to enable install it again without creating a new maven project? 2.如何修改现有的maven项目以使其能够再次安装而不创建新的maven项目?

In OSGi the combination of Bundle-SymbolicName and Bundle-Version is like the "primary key" of the bundle... you cannot install two bundles having exactly the same symbolic name and version. 在OSGi中, Bundle-SymbolicNameBundle-Version的组合就像是Bundle-Version的“主键”……您不能安装两个符号名称和版本完全相同的捆绑软件。

In your question you have mixed up tooling with runtime issues so it's hard to tell what's really happening... anyway, you have changed the artifactId in Maven but I have no idea what effect that might have on the Bundle-SymbolicName, which is what OSGi cares about. 在您的问题中,您将工具与运行时问题混为一谈,因此很难说出到底是什么情况……无论如何,您已经更改了Maven中的artifactId ,但我不知道对Bundle-SymbolicName可能产生什么影响OSGi在乎。 You can install this bundle twice if you change that header. 如果更改该标头,则可以安装两次该捆绑软件。

However this begs the question, why do you want to install the same bundle twice? 但这引出了一个问题,为什么您要两次安装同一捆绑包? This is very rarely useful. 这很少有用。 Please explain why you want to do this; 请说明为什么要这样做; it's likely there is a better solution to your underlying problem. 可能有更好的解决方案来解决您的潜在问题。

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

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