start an OSGI bundle
I'm creating a headless OSGI server that runs outside of Eclipse. I'm using Jetty as my Servlet container, and Equinox as my OSGI container. I'm using the org.eclipse.equinox.http.jetty
bundle to add Jetty to OSGI. It all runs correctly if I start jetty and org.eclipse.equinox.http.registry manually from the osgi>
prompt. However, I want this to run unattended, so I need to load those bundles automatically (or at least programatically) at OSGi startup. How do I do this?
In other words, how do I auto-start an OSGI bundle?
Another re-invent the wheel, but well. Take a look at how Apache Karaf does take care of all of this. Btw. it's a OSGi Container which supports to choose between different OSGi - runtimes. So in your scenario you need to have some sort of "main" that's loading your root bundle and tells it to load your initial set of bundles. In case of Karaf the initial set is handled by the main class, which is configurable. For the other bundles one might like to deploy, Karaf does have a Features deployer that will install all bundles in a given "features.xml". It's a descriptor telling the features service to deploying bundles from maven or obr repositories.
For details take a look at Karaf Main class. For more details about Karaf take a look at Apache Karaf
Just in case, you'll find a std. and a minimal distribution that might suite your needs.
Once you've installed the bundles from the osgi> prompt (or better start using gogo) then the installs are persistent. So when you restart the framework, your bundles should automatically be restarted.
There are some launcher settings that can delete the persistent information for you if you want to always start afresh, see the launching frameworks section in the OSGi Core specification.
An interesting possibility is to use bnd(tools). In bndtools you can develop, debug, and test your application with a bndrun
file. Once you're happy, you can export your app to an executable JAR (like java -jar myapp.jar). This executable jar will automatically start a framework with all included bundles.
If you want to update bundles dynamically then you could take a look at FileInstall. It is a bit simplistic but for smaller applications (<50 bundles) it works well. (and you can combine FileInstall with bndtools launcher).
链接地址: http://www.djcxy.com/p/74734.html上一篇: 全面支持OSGi捆绑软件
下一篇: 启动一个OSGI包