0

I have one bundle which has Import-Package org.osgi.service.cm. In this bundle there is only an interface ConfigurationInterface, that declares a couple of methods, one throws an org.osgi.service.cm.ConfigurationException. This bundle exports only its own package, lets say com.foo.bar.configuration.

Then I have other API bundles that have an interface for the service, ServiceInterface, that extends ConfigurationInterface, so they are importing the package com.foo.bar.configuration. Obviously there are also implementations bundle for these api that implement ServiceInterface, so they are importing org.osgi.service.cm because every implementations need to have the method that throws an org.osgi.service.cm.ConfigurationException.

Everything is working fine, the problems come out when I declare these services as optional, because when they are not available the framework tries to instantiate a proxy from the interface and I get a java.lang.ClassNotFoundException: org.osgi.service.cm.ConfigurationException. The framework suggests to add an import for 'org.osgi.service.cm' to the API bundle.

Is there a way to make this import available from the configuration bundle so that it is not necessary to add the import to every API?

ralight
  • 11,033
  • 3
  • 49
  • 59
  • "because when they are not available the framework tries to instantiate a proxy from the interface...": Just a piece of advice: Do not use any technology that does such "magic". Magic is the holy grail of half professional programmers. While it looks cool, it is evil, especially in the OSGi world. – Balazs Zsoldos Jul 10 '14 at 08:07
  • Which framework do you refer to? Felix or something else? – Christian Schneider Jul 10 '14 at 09:37
  • Are you sure you are not confusing package imports/exports and services / components? The first two paragraphs are about the former, while in the third paragraph you write "the framework tries to instantiate a proxy from the interface", which sounds like dependency injection from some component framework. – benjamin Jul 10 '14 at 19:19
  • @ChristianSchneider I'm using Felix. – denis85 Jul 14 '14 at 14:08
  • @BalazsZsoldos I don't think to use any "magic" technologies, I'm referring to the part of the felix framework that instantiates a null object for unavailable services. For the moment I added the import of org.osgi.service.cm to every api bundles and it works – denis85 Jul 14 '14 at 14:15
  • I think adding the import to every bundle that needs it is the only way to go. – Christian Schneider Jul 14 '14 at 14:20

0 Answers0