Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Invoke an OSGi Service from outside the OSGi Framework.?

I've planning to develop a web application using Java and based on some MVC framework. This application should support plugins.

So, I planning to create plugin using OSGI container(apache felix) and expose plugin as a service (using service registry feature of OSGI).

Both(web application and OSGI service) will be running in same JVM.

So, I need help on how can I use the OSGI service(plugin) outside OSGI container ?

I basically want to invoke exposed OSGI service outside OSGI, in this case in my web application.

Thanks in advance !

like image 477
parthiban Avatar asked Mar 10 '23 14:03

parthiban


1 Answers

To make this work you need to have the api package of the service in the classpath where you start the OSGi framework. You then need to export this package as a system package export. This is the only way how the bundle implementing the service and the non OSGi code can see the same service interface class.

You then use the FrameworkFactory to create a Framework instance which you can start. From the framework you can obtain the BundleContext and use it to obtain the service instance(s).

See embedding felix for some more details.

like image 197
Christian Schneider Avatar answered Mar 24 '23 13:03

Christian Schneider