2

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 ...

0

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

5 Comments

thx. this is a good idea. I also had the idea to create a tcp socket and listen to a specially port...
Yes, sockets is another idea, but probably is unnecessarily complicated.
How do the JUnit and TestNG plugins do it?
I believe they run JUnit as a separate process and monitor its state through the console output. In fact, many Eclipse plug-ins to external programs are simply running the command-line and monitoring output/logs.
I just posted that as an answer :)
1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.