views:

330

answers:

1

Hi,

im having a ClassLoader issue. Since im quite an osgi newby, hopefully the answer isn't that hard :)

I think it has to do with Compile vs. Runtime libraries. in Netbeans 6.7.1 project properties, the compiletime libs are always propagated to the other categories.. so i can't differentiate there.

When compiling the FelixHost the next jars are used

  • Felix.jar
  • osgi-core.jar
  • osgi-compendium.jar
  • osgi.service.obr-1.0.2.jar

But when running, the framework will load an implementation for OBR. This OBR bundle also contains the interface definitions. I think this is why there's a classCastException..

i actually want the FelixHost to work together with OBR to do some initial provisioning..

Any ideas are welcome.

+1  A: 

I assume that by "FelixHost" you are referring to your project that is encapsulating and launching the Felix framework.

The problem is that you have to be a bit careful about the boundary between "OSGi world" and "non-OSGi world". Everything that you put on the classpath for FelixHost (i.e. also all compile time dependencies in your case) is essentially living outside of the OSGi world, so it's not advisable to use bundles like "osgi.service.obr-1.0.2.jar" in this way.

As you pointed out if the OSGi framework also loads the "osgi.service.obr-1.0.2.jar" bundle you will get into ClassCastException because you have essentially two versions of the same classes (interfaces).

One possible solution to this problem is to separate your initial provisioning logic into a separate bundle and do the OBR related work from within the OSGi world. Then you can remove the compile dependency of FelixHost on "osgi.service.obr-1.0.2.jar" and only have one copy of OBR interfaces loaded.

Pavol Juhos
I actually have read about it in the spec., and while typing the question it became more and more clear to me. Thanks for the very clear info. I'm sure its also useful for other OSGi newbies :)
Houtman