ServiceLoader issues and locating folders inside the plugin

Hello,

I have written a plugin that is packed using the third option in http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Plugin+Structure:

Sample
   myrepository
      ... other jars and xml files ...
   lib
      my-api.jar

      my-impl.jar

      idea-plugin.jar
          META-INF/
             plugin.xml



However, I am facing some difficulties when the following code is executed:

1)

ServiceLoader.load(MyInterface.class)



It returns an empty Iterable, even though I am distributing my implementation in the same lib folder.


2) How do I fetch the path to myrepository ? This folder is packed together with my plugin.

Forgive me if these questions are too trivial, this is the first time I write an IDEA plugin.

My source is located in https://github.com/gastaldi/forge-intellij-idea-plugin


Best Regards,

George Gastaldi

5 comments

Hi George,

ServiceLoader can't find your classes because plugin's classes are loaded by a dedicated classloader and system classloader doesn't know about that. Anothe question is why do you use ServiceLoader at all?

You can use com.intellij.openapi.application.PathManager.getPluginsPath() to get information about plugins root dir and then navigate by the known relative path.

Denis

0

Hi Denis,

Thanks for the response. I use ServiceLoader because it's the way I designed the integration between my interface API and class IMPL.

As for the PathManager usage, what is the best way to retrieve the folder my plugin was installed INSIDE the folder specified by PathManager.getPluginsPath() ?



Best Regards,

George Gastaldi

0

Your plugin jar should be located at that plugins directory

Denis

0

Please sign in to leave a comment.