[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[equinox-dev] Problem with getContextClassLoader() and third party library
|
I'm trying to use Apache ActiveMQ in an OSGi bundle, running on Equinox. I'm having a problem where ActiveMQ tries to dynamically load classes for various network transports. The method in ActiveMQ that does this looks as follows:
private Class newInstance(Properties properties, String propertyPrefix) throws ClassNotFoundException, IOException {
String className = properties.getProperty(propertyPrefix + "class");
if (className == null) {
throw new IOException("Expected property is missing: " + propertyPrefix + "class");
}
Class clazz;
try {
clazz =
Thread.currentThread().getContextClassLoader().loadClass(className); // NPE!
} catch (ClassNotFoundException e) {
clazz = FactoryFinder.class.getClassLoader().loadClass(className);
}
return clazz;
}
In the line where I've added the comment "NPE", a NullPointerException is thrown, because getContextClassLoader() returns null.
I have read the article at
http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements, which suggests that the "Context Finder" should be installed by the framework as the default context classloader, and resolve things according to the usual OSGi class loading algorithm. In the threads I've checked however, getContextClassLoader() always returns null.
Am I missing something? (This is using the Eclipse SDK v3.2).
It works OK if I manually set the context classloader before calling into ActiveMQ (and resetting it afterwards), but that's very clunky so I'd really like to avoid that... Any suggestions would be very welcome.
Regards,
Jan