This template is based on the idea of this tutorial and will create three bundles for a typical OSGi service scenario:
@Component
) of the service interface@Reference
Requirements:
There are three projects created org.myorg.test.hello (api), org.myorg.test.hello.impl, and org.myorg.test.hello.consumer.
The three Java classes created (in each of the projects) are shown in the edit window (HelloService, HelloServiceImpl, HelloServiceConsumer).
If desired, the user can use Eclipse refactoring to rename the default service method (named methodName) to (e.g.) hello, resulting in:
Included in the generated org.myorg.test.hello
project is a Hello.bndrun
file that can be used to launch a framework, register the HelloServiceImpl, inject (via SCR) into the HelloServiceConsumer and have the HelloServiceConsumer call the service.
Click Resolve
and the Update
to let bndtools figure out the bundles to run (-runbundles).
Then clicking on Run OSGi (or Debug OSGi). Results in the service method being called and the console output.
Now you have a good starting point to develop your service.
In an existing project you probably do not need the generated consumer bundle if you already have other bundles consuming the service. Feel free to remove this generated bundle then (you may need to remove this bundle from the .bndrun
-runbundles
section).