tmy
tmy

Reputation: 25

Eclipse OSGi fragment with Export-Package

I have two bundles, one of it being a host bundle for two fragment and the following dependencies between this bundles/fragments.

In eclipse (i use oxygen but same error on neon3) there is an error that the import from A to B1.b1package cannot be resolved. I read that using the line Eclipse-ExtensibleAPI: true (Eclipse Help Page) solves this problem by telling the PDE the fragment is allowed to export additional packages (at runtime the fragments are always allowed to do this, the setting is just an information for the PDE)

But after using this setting eclipse complains about a cycle in my dependecies which doesn't exist at runtime because fragment B2 has an dependency on bundle A...

What is the correct way to handle such problems?

Upvotes: 1

Views: 324

Answers (1)

Tim Ward
Tim Ward

Reputation: 1199

What is the correct way to handle such problems?

From an OSGi perspective the correct thing to do is actually to separate the API types completely (ideally into separate bundles) and to use the OSGi service registry to intercommunicate. This ensures that you don't have cycles in the package dependency graph, and allows you to easily release updates knowing that the API has not changed. Declarative Services provides a simple, annotation-based injection model that PDE can process for you.

A model with:

  • API Bundle A (Exports package A.apackage)
  • API Bundle B (Exports packages B.bpackage, B1.b1package)
  • Impl Bundle A (Imports all three packages, provides A.apackage.AService)
  • Impl Bundle B (Imports B.bpackage, provides B.bpackage.BService)
  • Impl Bundle B1 (Imports B1.b1package, provides B1.b1pacakge.B1Service)
  • Impl Bundle B2 (Imports A.apackage)

may work better for you.

Upvotes: 1

Related Questions