You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Alex Wei <oz...@gmail.com> on 2009/06/10 05:04:42 UTC

How to instruct bnd to import packages that have classes instantiated via reflection?

Hi all,
I'm trying to use maven bundle plugin to generate the Import-Package header
for packages that only contain classes that are only referenced via
reflection. These are from a third-party library.

For example, this library contains:
com.foo.type.Foo
com.foo.type.impl.FooImpl
com.foo.service.FooService
com.foo.service.properties

FooService reads foo.properties and find out what classes implement Foo and
instantiate it.

Now because there are two bundles (bundle 0 and bundle 9) exposing this
library. If the packages are imported from bundle 0, the code will break
because bundle0 does not export some required third-party library packages
(which again contains classes instantiated via reflection). If the packages
are imported from bundle 9, it works.

So I need to instruct bnd to import packages from bundle 9.

I put in the following code:
<Require-Bundle>bundle9.name</Require-Bundle>
<Import-Package>com.foo*;com.foo.type*;com.foo.type.impl*;bundle-symbolic-name="
bundle9.name"</Import-Package>

But the generated MANIFEST.MF has only the following:
com.foo.type;bundle-symbolic-name="bundle9.name",
com.foo.service;bundle-symbolic-name="bundle9.name"

com.foo.type.impl is missing.

So when this is deployed, I got this from FelixOsgiContainerManager:
Constraint violation for 16.0 detected; module can see com.foo.type.impl
from [9.0] and com.foo.type.impl from [0].

It seems bnd tool somehow determines the classes in the impl sub-package are
not used and then does not include the instructions explicitly spelled out
for this package.

Is there a way to override this behavior?

Thanks in advance.
Alex