You have to check the javadoc, java.lang.ClassLoader
, doesn't implement the addURL()
method, it is implemented by java.net.URLClassLoader
. The CompoundClassLoader
is not extending it. So to be safe you should always check using instanceof
. If not, you can try to find the correct class loader higher in the stack using the methods getParent()
or getSystemClassLoader()
.
Q: Does this error have anything to do with the "Parent Last" setting in Websphere? Why?
Not exactly. However it is related to modularity of class loaders in WebSphere. In default settings, each module is loaded by a separate classloader and it happens that module classloader is not extending URLClassLoader
. If you would switch the server classloader policy to Single for the server, then it would use single classloader for all applications however it is still a hierarchy, so it will not solve your issue. Check this link for details about WebSphere Classloaders.
Quoting the article
When the application class-loader policy is set to Single, then a
single application class loader loads all EJB modules, dependency JAR
files, and shared libraries in the system. When the application
class-loader policy is set to Multiple, then each application receives
its own class loader that is used for loading the EJB modules,
dependency JAR files, and shared libraries for that application.
But for your issue maybe you should consider adding ojdbc6.jar
as a shared library? Then you would not need to embed code for loading it in the application?
Here is sample code to see the classloader hierarchy:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
do {
System.out.println(classLoader.getClass().getName());
System.out.println("Is URLClassLoader: " + (classLoader instanceof URLClassLoader));
classLoader = classLoader.getParent();
} while(classLoader != null);
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
System.out.println("System: " + systemClassLoader.getClass().getName());
System.out.println("Is URL: " + (systemClassLoader instanceof URLClassLoader));
And output:
SystemOut O com.ibm.ws.classloader.CompoundClassLoader
SystemOut O Is URLClassLoader: false
SystemOut O com.ibm.ws.classloader.CompoundClassLoader
SystemOut O Is URLClassLoader: false
SystemOut O com.ibm.ws.classloader.ExtJarClassLoader
SystemOut O Is URLClassLoader: false
SystemOut O com.ibm.ws.classloader.ProtectionClassLoader
SystemOut O Is URLClassLoader: false
SystemOut O com.ibm.ws.bootstrap.ExtClassLoader
SystemOut O Is URLClassLoader: true
SystemOut O org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader
SystemOut O Is URLClassLoader: false
SystemOut O sun.misc.Launcher$AppClassLoader
SystemOut O Is URLClassLoader: true
SystemOut O sun.misc.Launcher$ExtClassLoader
SystemOut O Is URLClassLoader: true
SystemOut O System: sun.misc.Launcher$AppClassLoader
SystemOut O Is URLClassLoader: true