felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stuart McCulloch" <stuart.mccull...@jayway.net>
Subject Re: two bundles with same package problem
Date Fri, 11 Apr 2008 14:29:17 GMT
On 11/04/2008, Sergey Parilin <parilinsa@gmail.com> wrote:
>
> Ops, sorry. It was a mistake in the example. It was because
> maven-bundle-plugin don't add not exporting package in to the bundle
> archive. You must delete Export-Package directive from
> bundle2/osgi.bnd and rebuild and rerun it. Or there is a fixed version
> in attachment. For now classes in second bundle in org.foo are
> present, but bundle2 still can't find org.foo.ExampleService2 and I
> have this response:
> java.lang.NoClassDefFoundError: *** Package 'org.foo' is imported by
> bundle 2 from bundle 1, but the exported package from bundle 1 does
> not contain the requested class 'org.foo.ExampleService2'. Please
> verify that the class name is correct in the importing bundle 2 and/or
> that the exported package is correctly bundled in 1. ***
> But class org.foo.ExampleService2 presented in bundle2


this is a classic "split-package" problem, where you have
two bundles exporting the same package but with different
content (which is usually a bad idea)

in OSGi only one bundle will be chosen as the "exporter"
of a given version of a package, so you will see missing
class problems like you mention with split-packages.

see section 3.13 of the OSGi spec for more discussion of
split-packages, and a solution (Require-Bundle). However,
note that there are side-effects of using Require-Bundle
that mean it should be used very sparingly, usually when
integrating legacy code with OSGi where you don't have
control over the package content

for new projects where you can refactor your code, it's
advisable to ensure that there's only one set of content
for a given package, as this is much more maintainable
and you get the most out of OSGi wrt. dynamic upgrades

I often suggest also putting the API/SPI package(s) into
a separate bundle than the implementation, as this makes
it much easier to swap implementations at runtime.

HTH

2008/4/11, Karl Pauls <karlpauls@gmail.com>:
>
> > You don't include the org.foo package inside your second bundle (i.e.,
> >  there are no classes in the org/foo dir). That is why you can't find
> >  the classes.
> >
> >  Felix and Kf's behaviour is the correct one. Since the bundle that
> >  exports the package actually doesn't have anything to export the
> >  classes can not be found. It probably only works on Equinox because
> >  they do bootdelegate to the classpath by default (which is bad). Just
> >  make sure your bundle contains the org.foo package and it should work.
> >
> >  regards,
> >
> >  Karl
> >
> >
> >  On Fri, Apr 11, 2008 at 2:55 PM, Sergey Parilin <parilinsa@gmail.com>
> wrote:
> >  > Thanks for the quick answer.
> >  >
> >  >  Here they are.
> >  >
> >  >  This is the first:
> >  >
> >  >  Manifest-Version: 1.0
> >  >  Export-Package: org.foo;version="1.0.0.SNAPSHOT"
> >  >  Private-Package: org.foo.internal
> >  >  Ignore-Package: org.foo.internal
> >  >  Built-By: sap
> >  >  Tool: Bnd-0.0.227
> >  >  Bundle-Name: org.foo.test-osgi.bundle1 [org.foo]
> >  >  Created-By: Apache Maven Bundle Plugin
> >  >  Build-Jdk: 1.6.0_03
> >  >  Bundle-Version: 1.0.0.SNAPSHOT
> >  >  Bnd-LastModified: 1207917736196
> >  >  Bundle-ManifestVersion: 2
> >  >  Bundle-Activator: org.foo.internal.ExampleActivator1
> >  >  Bundle-Description: Generated using Pax-Construct v2
> >  >  Import-Package: org.foo;version="1.0.0.SNAPSHOT",org.osgi.framework
> >  >  Bundle-SymbolicName: org.foo.test-osgi.bundle1
> >  >
> >  >  This is the second:
> >  >
> >  >  Manifest-Version: 1.0
> >  >  Private-Package: org.foo.internal
> >  >  Ignore-Package: org.foo.internal
> >  >  Built-By: sap
> >  >  Tool: Bnd-0.0.227
> >  >  Bundle-Name: org.foo.test-osgi.bundle2 [org.foo]
> >  >  Created-By: Apache Maven Bundle Plugin
> >  >  Build-Jdk: 1.6.0_03
> >  >  Bundle-Version: 1.0.0.SNAPSHOT
> >  >  Bnd-LastModified: 1207917736734
> >  >  Bundle-ManifestVersion: 2
> >  >  Bundle-Activator: org.foo.internal.ExampleActivator2
> >  >  Bundle-Description: Generated using Pax-Construct v2
> >  >  Import-Package: org.foo;version="1.0.0.SNAPSHOT",org.osgi.framework
> >  >  Bundle-SymbolicName: org.foo.test-osgi.bundle2
> >  >
> >  >  Also, I have attached my example as an archive.
> >  >  You can extract it. Build and execute with maven2.
> >  >  mvn clean install
> >  >  mvn -Dframework=felix pax:provision
> >  >  or
> >  >  mvn -Dframework=equinox pax:provision
> >  >
> >  >  to feel a difference.
> >  >
> >  >  2008/4/11, Marcel Offermans <marcel.offermans@luminis.nl>:
> >  >
> >  >
> >  > > On Apr 11, 2008, at 13:13 , Sergey Parilin wrote:
> >  >  >
> >  >  >
> >  >  > > I have two bundles (A and B). Bundle A have package org.foo and
> >  >  > > imports it.
> >  >  > >
> >  >  >
> >  >  >  Could you please show us both manifests, because I'm not sure I
> completely
> >  >  > understand your story.
> >  >  >
> >  >  >  Greetings, Marcel
> >  >  >
> >  >  >
> >  >
> >
> >
> >
> >
> > --
> >  Karl Pauls
> >  karlpauls@gmail.com
> >
>
>


-- 
Cheers, Stuart

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message