views:

32

answers:

1

I changed my Java SE (right button click on project Configure -> Convert to Plug-in Projects) to plug -in, but when i try to run it - it run as Eclipse application, how to start it as OSGi? Thanks!

+1  A: 

Converting a JavaSE application into a single, big bundle basically means that you're launching your code in a different way. Instead of the public static void main(String[] args) you now implement the BundleActivator interface which has a start() and a stop() method (each with a BundleContext as argument).

Launching that depends a bit on what framework implementation you chose. Since OSGi 4.2 there is a launcher API (paragraph 6.2 of the spec) which specifies a universal mechanism to launch a framework and run your single bundle. If you use an older implementation, launching is framework specific and I can only refer you to the documentation of that framework.

Marcel Offermans
Would you recommend a OSGi 4.2 compliant implementation?
Thorbjørn Ravn Andersen
If I will start to run my application via method of BundleActivator , how can it interact with bundles in fraemwork?
EK
@Thorbjørn: Yes, I would recommend using the latest release of the specification.@EK: Technically, you launch the framework and it will invoke the start method of a class you specify that implements BundleActivator. The BundleContext that is passed as an argument to the start (and stop) methods is your interface to the framework. It allows you to interact with the service registry amongst other things. Services are the main mechanism for bundles to interact. You can both publish and lookup services via the BundleContext. For more info, I would recommend an introduction to OSGi.
Marcel Offermans
Thanks, I can see my question could be interpreted about if at all. I was thinking of if you would recommend any particular implementation?
Thorbjørn Ravn Andersen
Indeed, I interpreted your question the wrong way. :) Personally I would recommend using Apache Felix, I have used it in many projects over the years. In fact, I'm one of the committers, working on it, so I'm not unbiased. In all honesty though, one of the strengths of OSGi is that it has multiple, compatible implementations so Equinox and Knopflerfish work just fine too and I would definitely recommend testing your code in multiple frameworks (using for example Pax Runner to launch a framework and version of your choice and Pax Exam to run tests in any of these).
Marcel Offermans