从eclipse插件项目运行program.exe

时间:2015-06-26 08:52:53

标签: java cmd eclipse-plugin runtime exe

我正在编写一个运行program.exe的eclipse-plugin。我已将program.exe添加到插件jar文件中。如何执行这个程序?

public class Handler extends AbstractHandler {
    public Object execute(ExecutionEvent event) throws ExecutionException {
        Runtime.getRuntime().exec(/*What should I write here*/);
        return null;
    }
}

2 个答案:

答案 0 :(得分:2)

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);

This will find the program in the plugin jar and extract it to a temporary location (done by FileLocator.toFileURL).

答案 1 :(得分:0)

您应该像在cmd中一样执行程序,但现在指定程序位置的整个路径。

Runtime.getRuntime().exec("C:\\your\\path\\program.exe");

Runtime class的Oracle文档中,您可以在exec()中看到可接受的输入。