javaeclipse-plugincomponentsosgi-bundlekura

Should every component(.xml) have its own eclipse-project?


So I learning how to use eclipse-kura to implement IoT-applications. My question is, should every Component have its own eclipse-project/bundle or if multiple Components can be in the same bundle (as in my OSGI-INF would contain 2 Component Definitions for 2 different classes).

I couldn't find any examples for this anywhere. As I am a beginner at this and am trying to understand the concepts any hint would be appreciated.


Solution

  • Short answer: it is up to you.

    Long answer: You can do it however you like ;)

    There is no rule in OSGi that forbids to put several components (classes that are declarative services and are annotated with @Component) in one bundle. It depends however a little on how you define the boundaries of your bundles, i.e., do you create a bundle per functionality or do you create a bundle per layer in a x-tiered application (e.g. one bundle for db, one bundle for logic and one bundle for GUI). Those examples were completely arbitrary, but you can see that depending on how you define the scopes of your bundles it sometimes would make sense to put several components within one bundle and sometimes not so much.

    Regarding on how I would recommend to structure bundles:

    Maybe a good example can be found in the examples of OSGi enRoute: https://enroute.osgi.org/Tutorial/

    Kind regards, Thomas