How to load classes from other plugins?

Answered

I am writing a plugin (lets call it Plugin_M) that should load specific classes from other additional plugins (that work as extensions to the plugin I am working on).

My plugin Plugin_M works, with "ServiceLoader.load"  it loads successfully all necessary classes that are inside the plugin zip file (i.e. Plugin_M.zip/Plugin_M/lib/...). I installed it using the "Install Plugin from Disk..." menu point.

However, now I have an "extension" plugin (Plugin_E) that I also installed using the "from disk" menu point. It contains a file "Plugin_E.zip/Plugin_E/lib/Plugin_E.jar/META-INF/services/important.signature.of.interface.in.Plugin_M" in which a class of Plugin_E is described.

I want that this class of Plugin_E gets loaded by the Plugin_M when it uses "ServiceLoader.load(important.signature.of.interface.in.Plugin_M.class)". Is that somehow possible?

The alternative I am thinking about is using "URLClassLoader" to load the extensions from a specified directory instead of registering them through the IDE plugin system.

Please sign in to leave a comment.