如何让Java运行可执行应用程序?

码:

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?

new ProcessBuilder("mvn"); 没有像mvn.exemvn.bat这样的扩展名,它可以让您的应用程序将其作为文件夹读取。