从 Eclipse 插件项目运行 program.exe
我正在编写一个运行 program.exe 的 eclipse 插件.我已将 program.exe 添加到插件 jar 文件中.如何执行这个程序?
I am writing an eclipse-plugin witch run program.exe. I have added program.exe to plugin jar file. How can a execute this program?
public class Handler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
Runtime.getRuntime().exec(/*What should I write here*/);
return null;
}
}
推荐答案
无法从插件jar中运行program.exe,需要解压.在您的插件中使用:
You can't run the program.exe from inside the plugin jar, so it needs to be extracted. In your plugin use:
Bundle bundle = Platform.getBundle("plugin id");
URL url = FileLocator.find(bundle, new Path("relative path to program"), null);
url = FileLocator.toFileURL(url);
这将在插件 jar 中找到程序并将其解压缩到一个临时位置(由 FileLocator.toFileURL
完成).
This will find the program in the plugin jar and extract it to a temporary location (done by FileLocator.toFileURL
).
相关文章