使用流程构建器生成JVM

时间:2014-04-03 00:56:17

标签: java jvm processbuilder

我正在尝试使用processbuilder在eclipse中使用java 7 u51生成一个新的JVM。不幸的是,当processBuilder尝试使用它时,我遇到路径问题(String path = System.getProperty("java.home");)。

以下是问题代码

String separator = System.getProperty("file.separator");
String classpath = System.getProperty("java.class.path");
String path = System.getProperty("java.home");
System.out.println("Seperator = " + separator + " classpath = " + classpath + " path = " + path);

ProcessBuilder processBuilder = new ProcessBuilder(path, "-cp", 
    classpath, Transcriber.class.getName());
Process process = processBuilder.start();

以下是控制台输出

java.io.IOException: Cannot run program "C:\Program Files\Java\jre7": CreateProcess error=5, Access is denied
Unable to call transcribeConvo
    at java.lang.ProcessBuilder.start(Unknown Source)
    at TranscribePanel$2.run(TranscribePanel.java:131)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=5, Access is denied
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 7 more

我尝试将jvm.dll直接添加到eclipse.ini但它没有影响。任何帮助都会很棒。谢谢:))

Ps:如果我没有提供足够的信息,请告诉我。

1 个答案:

答案 0 :(得分:0)

路径“C:\ Program Files \ Java \ jre7”不是可执行文件的路径,因此是错误。如果你想执行java可执行文件,那么你需要实际提供它的完整路径,可能是“C:\ Program Files \ Java \ jre7 \ bin \ java.exe。”