代码:
ProcessBuilder pb = new ProcessBuilder("mvn");
Process p = pb.start();
输出:
java.io.IOException: Cannot run program "mvn": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at com.littleHelper.app.ButtonDemo.actionPerformed(ButtonDemo.java:47)
可是:
ProcessBuilder pb = new ProcessBuilder("mvn.bat");
Process p = pb.start();
完美运行。但在cmd中运行良好!如何让java像cmd一样运行?
答案 0 :(得分:1)
new ProcessBuilder("mvn");
没有类似mvn.exe
或mvn.bat
的扩展程序,导致您的应用程序将其作为文件夹读取。