从eclipse插件项目运行program.exe(Run program.exe from eclipse plugin project)

412 IT屋

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;
    }
}
解决方案

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

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



  public class Handler extends AbstractHandler {
public Object execute(ExecutionEvent event)throws ExecutionException {
Runtime.getRuntime()。exec(/ *我应该在这里写什么* /);
返回null;
}
}

解决方案

你无法从插件jar中运行program.exe,因此需要解压缩。在你的插件中使用:



  Bundle bundle = Platform.getBundle(plugin id); 

URL url = FileLocator.find(bundle,new Path(程序的相对路径),null);

url = FileLocator.toFileURL(url);


这将在plugin jar中找到该程序并将其解压缩到临时位置(由code> FileLocator.toFileURL )。


本文地址:IT屋 » 从eclipse插件项目运行program.exe