gpt4 book ai didi

java.io.IOException : Cannot run program ".\bin\catalina.bat" - CreateProcess error=2, 系统找不到指定的文件

转载 作者:行者123 更新时间:2023-11-28 22:52:24 33 4
gpt4 key购买 nike

尝试使用 Java 启动 Tomcat 进程时出现以下错误。

java.io.IOException: Cannot run program ".\bin\catalina.bat" (in directory "C:\Users\chiranga93\Documents\GitHub\product
-as\integration-tests\target\wso2as-6.0.0-SNAPSHOT"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at org.wso2.appserver.test.integration.TestSuiteListener.startPlatformDependApplicationServer(TestSuiteListener.
java:152)

用于此的代码段如下:

        ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.directory(appserverHome);
processBuilder.environment().put("JAVA_OPTS", jacocoArg);

if (os.toLowerCase().contains("windows")) {
log.info("Starting server as a " + os + " process");
return applicationServerProcess = processBuilder.command("\\bin\\catalina.bat", "run").start();
} else {
log.info("Starting server as a " + os + " process");
return applicationServerProcess = processBuilder.command("./bin/catalina.sh", "run").start();
}

CATALINA_HOME\bin\catalina.bat 文件存在于 bin 文件夹中。但它指定特定文件不存在。

我该如何解决这个问题?

最佳答案

调用 processBuilder.directory(File) 仅为创建的进程设置工作目录,但不用于命令字符串本身。

因此使命令成为绝对路径,例如

if (os.toLowerCase().contains("windows")) {
String catalinaPath = new File(appserverHome, "bin\\catalina.bat").getAbsolutePath();
return applicationServerProcess = processBuilder.command(catalinaPath, "run").start();
} ...

关于java.io.IOException : Cannot run program ".\bin\catalina.bat" - CreateProcess error=2, 系统找不到指定的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36337267/

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