开发者

call a own eclipse plugin method from any java application

I would l开发者_C百科ike to do following:

Create a own Eclipse Plugin, that (for example) just has one method "sayHello" that displays a message "hello world".

so for so good.

But now I want to let the users, that have my plugin installed, call this method from their java code. something like that:

//[...]
org.jjoe64.my_eclipse_plugin.Plugin.sayHello(); // of course this won't work...
//[...]

has anybody an idea how to do this? I think it's a little bit more complicate ...


Basically you want to call a running plug-in from code compiled and running from Eclipse. Because these are two separate processes there is no simple way to directly invoke a method.

One simple solution is to have your plug-in poll a temporary file it creates in the user's workspace.

class Plugin {
   void Activate() {
      while (true)
         if (temporaryFile.hasChanged())
            doSomething();
   }
}

Create a library your user imports to their project. They call a function in that library that updates the file:

class PluginCaller {
    static void sendMessageToPlugin(String message) {
         temporaryFile.append(message);
    }
}

When your plug-in sees there has been a change, it acts as though the method was called.


JUnit has the same problem. It solves it by running having user-visible static method spawn a separate process, whose state the plugin monitors. In fact, many Eclipse plug-ins to external programs are simply running the command-line and monitoring output/logs. (via Garrett Hall)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜