gpt4 book ai didi

java - 无法识别的选项 : -cp with ProcessBuilder on Windows only

转载 作者:可可西里 更新时间:2023-11-01 14:42:54 28 4
gpt4 key购买 nike

所以我正在开发一个跨平台 Bootstrap ,它在 OSX/Linux 上可以正常工作,但在 Windows 中返回以下错误消息:

Error: Could not create the Java Virtual Machine.Error: A fatal exception has occurred. Program will exit.Unrecognized option: -cp C:/myapp/realm/bin/Launcher.jar;C:/myapp/_jvm/jre/../lib/tools.jar;C:/myapp/realm/shared/lib/jetty-util-8.1.4.v20120524.jar

如果我打印出我的 ProcessBuilder 参数列表并在命令行上运行这些参数,它将成功运行。命令应该是

C:/myapp/_jvm/jre\bin\java -javaagent:C:/myapp/realm/bin/spring-agent.jar -cp C:/myapp/realm/bin/Launcher.jar;C:/myapp/_jvm/jre/../lib/tools.jar;C:/myapp/realm/shared/lib/jetty-util-8.1.4.v20120524.jar-Xmx256m -Xms200m -Xss128k -XX:+UseBiasedLocking -XX:+UseNUMA -DprocessType=realm -Dcert.framework.license=C:/myapp/realm/license/my.license -Djava.security.policy=C:/myapp/realm/security/java.policy -Djava.security.properties=C:/myapp/realm/security/java.security -Djava.security.auth.login.config=C:/myapp/realm/security/jaas.conf -Drealm.home=C:/myapp/realm -Duser.dir=C:/myapp/realm/bin -Djava.endorsed.dirs=C:/myapp/realm/endorsed;C:/myapp/_jvm/jre/lib/endorsed -Djava.ext.dirs=C:/myapp/realm/ext;C:/myapp/_jvm/jre/lib/ext -Dlog4j.configuration=file:C:/myapp/realm/conf/log4j.properties -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger com.myapp.launcher.ProviderLauncher

我已经尝试在类路径周围放置引号,使用双斜杠等无济于事,我们将不胜感激。这是代码:

   String mainClass = args[0];
String propFile = args[1];
FileInputStream fis =new FileInputStream(propFile);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = null;
ArrayList<String> argList = new ArrayList<String>();
while((line = br.readLine()) != null){
if(line.startsWith("#"))
continue;
String trimmedLine = line.trim();
if(trimmedLine.isEmpty())
continue;
Matcher m = p.matcher(trimmedLine);
StringBuffer sb = new StringBuffer();
while(m.find()){
String content = m.group(1);
String envContent = System.getenv(content);
if(envContent == null || envContent.isEmpty())
envContent = System.getProperty(content);
m.appendReplacement(sb, envContent);
}
m.appendTail(sb);
if(!sb.toString().startsWith("\"-") && !sb.toString().startsWith("-") && argList.size() > 0)
argList.set(argList.size()-1, argList.get(argList.size()-1)+File.pathSeparator+sb.toString());
else argList.add(sb.toString());
}

ArrayList<String> cmdList = new ArrayList<String>();
cmdList.add(System.getenv("JAVA_HOME") + File.separator + "bin" + File.separator + "java");
cmdList.addAll(argList);
cmdList.add(mainClass);
System.out.println(cmdList.toString());
ProcessBuilder pb = new ProcessBuilder(cmdList);
new ProcessBuilder(line);
File f = new File(System.getenv("MY_DIR") + File.separator + "logs" +File.separator + "provider-console.log");
if(!f.exists())
f.createNewFile();
pb.redirectErrorStream(true);
pb.redirectOutput(f);
pb.directory(new File(System.getenv("MY_DIR") + File.separator + "bin"));
Process p = pb.start();

这是 toStringed cmdList:

[C:/myapp/_jvm/jre\bin\java, -javaagent:C:/myapp/realm/bin/spring-agent.jar, -Xmx256m, -Xms200m, -Xss128k, -XX:+UseBiasedLocking, -XX:+UseNUMA, -cp C:/myapp/realm/bin/Launcher.jar;C:/myapp/_jvm/jre/../lib/tools.jar;C:/myapp/realm/shared/lib/jetty-util-8.1.4.v20120524.jar, -DprocessType=realm, -Dcert.framework.license=C:/myapp/realm/license/jericho.license, -Djava.security.policy=C:/myapp/realm/security/java.policy, -Djava.security.properties=C:/myapp/realm/security/java.security, -Djava.security.auth.login.config=C:/myapp/realm/security/jaas.conf, -Drealm.home=C:/myapp/realm, -Duser.dir=C:/myapp/realm/bin, -Djava.endorsed.dirs=C:/myapp/realm/endorsed;C:/myapp/_jvm/jre/lib/endorsed, -Djava.ext.dirs=C:/myapp/realm/ext;C:/myapp/_jvm/jre/lib/ext, -Dlog4j.configuration=file:C:/myapp/realm/conf/log4j.properties, -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger, com.myapp.launcher.ProviderLauncher]

最佳答案

“-cp”和实际类路径需要是 args 列表中的单独条目,您目前似乎将它们作为一个条目,用空格分隔。

关于java - 无法识别的选项 : -cp with ProcessBuilder on Windows only,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12592258/

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