ClassLoader question Follow
This is not OpenAPI-specific, but it is an attempt to allow my plugin to see jars located in IDEA/lib/ant.
<![CDATA[ ClassLoader classLoader = new URLClassLoader(/*urls of files from lib/ant*/); final Class consoleClass = classLoader.loadClass(AntConsole.class.getName()); console = (AntConsole) consoleClass.newInstance(); //now some checking: classLoader.loadClass("org.apache.tools.ant.launch.Locator"); //<-- works consoleClass.getClassLoader().loadClass("org.apache.tools.ant.launch.Locator"); //<-- throws NoClassDefFound ]]>
I suspect that AntConsole class has been already loaded and cached by some of classLoader's parents, with antConsole.class.getClassLoader() == this parent ClassLoader. As far as this parent loader doesn't see Locator class, I'm getting an exception. But is there some way to overcome this?
Please sign in to leave a comment.
Hello, Konstantin!
You wrote on Wed, 7 Jul 2004 12:55:43 +0400 (MSD):
KS> //now some checking:
KS> classLoader.loadClass("org.apache.tools.ant.launch.Locator"); //<--
KS> works
KS> consoleClass.getClassLoader().loadClass("org.apache.tools.ant.launch.
KS> Locator"); //<-- throws NoClassDefFound
Since 2008 build IDEA have dedicated classloaders for plugin. Plugin can see
classes of IDEA/lib, plugin can see classes of pluginHome/lib, but IDEA will
not know about plugin classes.
Mistake as in this sample, then you try to load clases from plugins lib by
ClassLoader from IDEA/lib, it will not work. But plugin classloader will
success work with IDEA/lib.
WBR,
--
Alexey Efimov, Java Developer
Tops-BI
http://www.topsbi.ru
I'm working in the context of this plugin classloader and classes from idea/lib can be seen. But I'm trying to make classes from idea/lib/ant to be accessible. Feel the difference :)
Alexey Efimov wrote:
It may see them, but it sure as hell has issues loading alot of them. I
have to bastardized jdom.jar to include parts of xpath in my plugin just
so I can use it now :(