2
votes

I would like 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 ...

2

2 Answers

4
votes

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.

1
votes

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)