我想从Java调用build.xml。为此,我在Java主方法中提到了下面的代码:
Process process;
try {
process = new ProcessBuilder("ant","-f" ,"D:/Selenium/Workspace/test_project/build.xml").start();
process.waitFor();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null)
{
System.out.println(line);
}
} catch (Exception e)
{
e.printStackTrace();
}
但是我得到错误:
java.io.IOException: Cannot run program "ant": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at com.gui.test.TestClass_Base.main(TestClass_Base.java:155)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 2 more
请帮。
似乎ant
不在您的路径上。所以它找不到它
还是……它找不到这个文件:
D:/Selenium/Workspace/test_project/build.xml
我不太确定。两个都检查一下,看看是否有帮助。
Windows上的Ant入口点是一个批处理脚本ant.bat
。批处理脚本必须在命令解释器(如cmd.exe
)中运行。
试试这个:
new ProcessBuilder("cmd.exe","/c","ant","-f","D:/Selenium/Workspace/test_project/build.xml")