RCP编程技巧:如何调用外部程序?

来源:互联网 发布:怎样预防网络诈骗 编辑:程序博客网 时间:2024/04/30 23:22
在RCP开发程序过程中,一项功能是调用ant对生成好的文件进行编译,那该如何在rcp中调用外部程序呢?
一开始,我试了如下的方法:
Runtime run = Runtime.getRuntime();
String build = GeniusUtil.getPath()+ "ant/bin/ant -buildfile "+ Project.projectTargetPath+ "\\build.xml";
run.exec(build);
结果系统报错如下:
java.io.IOException: CreateProcess: c:/MyData/Java/eclipse3.11/GeniusPlatform/ant/bin/ant -buildfile C:\MyData\Java\example\build.xml error=193


经过调试,用以下的方法终于成功:
Runtime run = Runtime.getRuntime();
String build = GeniusUtil.getPath() + "ant/bin/ant -buildfile "+Project.projectTargetPath+ "\\build.xml";
run.exec(new String[] {"cmd.exe", "/c", build});
0 0