I have hit this problem with some OSS projects.  A workaround is to do
something like this in the code you own that calls into the OSS project:

ClassLoader osgi = getClass().getClassLoader();
ClassLoader thread = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(osgi);

try {
  // invoke your un-osgi-aware oss library
} catch (Throwable t) { }
finally {
  Thread.currentThread().setContextClassLoader(thread);
}

I can't vouch for whether this approach is sound or not.  I can vouch that
it has gotten me out of many an XML parsing pickle though...


-c

On Thu, Apr 15, 2010 at 5:24 PM, Dan H <[email protected]> wrote:

> Libraries such as Hibernate and StAX that use
> Thread.getContextClassLoader() do not work (well) in Felix / Karaf.
> From what I've read it's because the OSGi Alliance never got around to
> specifying how this method should behave in an OSGi environment.
>
> I was wondering if it is possible in theory to create a bundle that
> provides a "correct" thread context classloader for all other bundles?
> I imagine it would involve writing a custom delegating classloader and a
> bundle listener that basically just make all exported classes from any
> bundle visible to the thread context classloader. However, I don't see a way
> to reliably set the context classloader since the main thread is managed by
> Felix.
>
> -Dan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to