|
|
|
|
|
Re: 2 versions of log4j-core.jar [message #127220 is a reply to message #127131] |
Mon, 09 March 2009 23:01 |
Tom H Messages: 18 Registered: July 2009 |
Junior Member |
|
|
In order to debug as suggested, I added the following code snippet to my
Application.java in order to examine the potential conflicts:
****
printClassLoaders(this, 0);
Object instance = null;
try {
instance = Loader.loadClass(
org.apache.log4j.ConsoleAppender.class.getName())
.newInstance();
...
}
System.out.println("Instance is not null");
printClassLoaders(instance, 0);
Appender appender;
appender = (Appender) instance;
****
printClassLoaders print the parent class loader chain back to the NULL
one. I get the following:
***
class my.Application,
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@ec436
....sun.misc.Launcher$AppClassLoader@12498b5
......null
class org.apache.log4j.ConsoleAppender,
sun.misc.Launcher$AppClassLoader@12498b5
....null
java.lang.ClassCastException: org.apache.log4j.ConsoleAppender
***
Looks like that my.Application is being loaded by the OSGI class loader,
but the instance object (which uses log4j helper classes) get's loaded
through AppClassLoader.
So the (instance, AppClassLoader) cannot be cast to Appender which is
(my.application, DefaultClassLoader).
Is my reasoning correct? The org.apache.log4j has internals that load
through some special mechanism which is not compatible with osgi loading:
*** Loader.loadClass
static public Class loadClass (String clazz) throws
ClassNotFoundException {
// Just call Class.forName(clazz) if we are running under JDK 1.1
// or if we are instructed to ignore the TCL.
if(java1 || ignoreTCL) {
return Class.forName(clazz);
} else {
try {
return getTCL().loadClass(clazz);
} catch(Throwable e) {
// we reached here because tcl was null or because of a
// security exception, or because clazz could not be loaded...
// In any case we now try one more time
return Class.forName(clazz);
}
}
}
***
|
|
|
Powered by
FUDForum. Page generated in 0.02784 seconds