所以我正在开发一个跨平台引导程序,该程序可以在 OSX/Linux 上正常工作,但在 Windows 中返回以下错误消息:
错误:无法创建 Java 虚拟机。错误:发生了致命异常。程序将会退出。无法识别的选项:-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 -Djav a.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/领域 /ext;C:/myapp/_jvm/jre/lib/ext -Dlog4j.configuration=file:C:/myapp/realm/conf/log4j.properties -Dorg.apache.commons.logging.Log=或 g.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 / 认可,-Djava.ext.dirs=C:/myapp/realm/ext;C:/myapp/_jvm/jre/lib/ext,-Dlog4j.configuration=file:C:/myapp/realm/conf/log4j。属性,-Dorg.apache.commons.logging.Log=org。apache.commons.logging.impl.Log4JLogger, com.myapp.launcher.ProviderLauncher]