Hello every one;
We are using Knopflerfish on top of our application server, and we would
like to jump to Felix.
But I have noticed that KF and Felix don't look like to behave similarly
when using libraries and
thread context class loader.
Because I don't want to bother you with the whole story of our context,
I have made a sample code
which illustrates the problem (if any, though).
Here it is: in the following bundle activator, I set the thread context
class loader, just before
instantiating a SAX xml reader:
package test;
import static java.lang.System.out;
import org.osgi.framework.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
try {
// Set the Thread CCL to my bundle class loader
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
// The following createXMLReader method will actually use the
TCCL for loading the class
// "com.sun.org.apache.xerces.internal.parsers.SAXParser"
which is located in the jdk.
XMLReader reader =
org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
out.println(reader);
} catch (Throwable t) {
t.printStackTrace();
}
}
...
Here is my corresponding manifest's Import-Package header:
Import-Package: org.osgi.framework,
org.xml.sax,
org.xml.sax.helpers
Please notice that I don't use the org.osgi.framework.bootdelegation
parameter neither with KF, nor
with Felix.
KnopflerFish (2.0.5) behavior:
---------------------------------------
When the createXMLReader() method is invoked, it tries to load the
"com.sun.org.apache.xerces.internal.parsers.SAXParser" using the
Thread CCL (which points to my
bundle CL) and gets an annoying ClassNotFoundException.
* My understanding is: createXMLReader() gets this exception because I
don't have imported the
failed package from my manifest.
* So I work around by adding a "DynamicImport-Package: *" in my
manifest and it works fine.
Felix (1.0.4) behavior:
----------------------------
Now, with Felix, all works just fine by default ! (without having to
provide
"DynamicImport-Package: *" in my manifest).
-> So far so good, but could any one please explain how Felix is able to
load the
com.sun.org.apache.xerces.internal.parsers package, even if I don't
have imported it from my
manifest ?
(I have checked the code in the createXMLReader() jdk method, and it
does not fall back to the jdk
bootstrap class loader if the TCCL don't find the class
com.sun.org.apache.xerces.internal.parsers.SAXParser ...)
Kind Regards
/Pierre
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]