gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 07:09:32 25 4
gpt4 key购买 nike

代码:

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 之类的扩展名,这会导致您的应用程序将其作为文件夹读取。

关于java - 如何让Java运行可执行应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20855438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com