Which classloader?
Hi
Could someone - possibly from JetBrains - please tell me which classloader I should be using to load module dependencies from within a plug-in? I am aware of the existence of IDEA's very own and the one for loading plug-in classes.
Also, what is the correct way of obtaining a reference to this classloader? I am trying to make all module dependencies visible to my plug-in at runtime and have yet to figure out how.
Thanks in advance for your help.
Regards,
Franck
Please sign in to leave a comment.
Maxim, Eugene, anyone?
Generally, you do not have to bother which classloader to use. Everything
should work automatically.
More precisely, everything in your plugin's lib folder jars is loaded with
plugin classloader, which has idea classloader as its parent.
So, any classes in IDEA's lib folder jars are loaded with idea classloader
and thus are shared between IDEA itself and all of the plugins.
If a certain plugin wants to take advandage of other plugin's API it should
declare a dependency (PLUGIN_ID]]> tag in plugin.xml). In
such a case plugin classloader will have all dependency plugin classloaders
as it's parent.
So, let's start from the problem you're trying to fight, OK?
-
Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"
Hi Maxim,
Thanks for the heads up. Perhaps I wasn't very clear, these dependencies are not runtime dependencies for the plug-in.
This is about the plug-in being able to see/load classes from libraries defined at the global/project/module-level and module classes.
Regards,
Franck
Oh, I see.
We do not load library classes into VM with any of classloader but instead
provide a PSI for them.
, so
PsiClass jbuttonclass = PsiManager.getInstance(project).findClass("javax.swing.JButton",
GlobalSearchScope.moduleWithLibrariesScope(module))
will find a class-file-based PsiClass for a JButton from the JDK assigned
to the module.
To get an introspection into library definitions themselves one could start
from ModuleRootManager.
-
Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"
Thanks for the prompt reply, I'll try your suggestions shortly.