OSGi how to install two identical bundle?

只谈情不闲聊 提交于 2019-12-13 03:12:17

问题


I want to install two identical bundle or the same bundle twice in OSGi container. The OSGi container I am using is FUSE ESB. Here is the bundle information:

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

change the artifact to

<artifactId>HelloWorldBundleCopy</artifactId>

change bean id to

<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

FUSE ESB OSGi container is installed in Host3. I need to run a service, for example HelloWorld on both Host1 and Host2. And this service is registered with FUSE ESB which is on Host3.

That is why I need to register the same bundle twice with 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? 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:

    FuseESB:karaf@root> install file:/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?


回答1:


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.

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. 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.



来源:https://stackoverflow.com/questions/16721457/osgi-how-to-install-two-identical-bundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!