从 Eclipse 插件项目运行 program.exe [英] Run program.exe from eclipse plugin project

查看:24
本文介绍了从 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).

这篇关于从 Eclipse 插件项目运行 program.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆