从任何java应用程序调用自己的eclipse插件方法 [英] call a own eclipse plugin method from any java application
问题描述
我想执行以下操作:
创建一个自己的Eclipse插件,(例如)只有一个方法sayHello显示一条消息hello world
Create a own Eclipse Plugin, that (for example) just has one method "sayHello" that displays a message "hello world".
所以很好。
但是现在我想让用户,有我的插件安装,从他们的java代码调用这个方法。这样的:
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 ...
推荐答案
基本上你想调用一个运行来自Eclipse的代码编译和运行的插件。因为这是两个独立的过程,所以没有简单的方法直接调用一个方法。
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.
这篇关于从任何java应用程序调用自己的eclipse插件方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!