我有以下方法可以正常工作:
private static boolean exec(String command,boolean printResults,boolean wait)
{
String Command_List[],Command_Array[]=command.split(" ");
Process p;
Result_String="";
Result_String_With_System_Prompt="";
try
{
Command_List=new String[Command_Array.length+2];
Command_List[0]="cmd";
Command_List[1]="/c";
for (int i=0;i<Command_Array.length;i++) Command_List[i+2]=Command_Array[i];
System.out.println("Command_List = "+Arrays.toString(Command_List));
ProcessBuilder pb=new ProcessBuilder(Command_List); // new ProcessBuilder("cmd","/c","java","-version");
pb.redirectErrorStream(true);
p=pb.start();
// Print the output. Since we read until there is no more input,this causes us to wait until the process is completed
if (printResults)
{
BufferedInputStream buffer=new BufferedInputStream(p.getInputStream());
BufferedReader command_Result=new BufferedReader(new InputStreamReader(buffer));
while ((Last_String=command_Result.readLine()) != null)
{
System.out.println(Last_String);
Result_String+=Last_String+"\n";
Result_String_With_System_Prompt+=Last_String+"\n"+System_Prompt;
}
command_Result.close();
}
}
catch (Exception e) { ... }
}
一切正常,直到今天早上,我看到Oracle的一个对话框窗口说Oracle JDK不再免费了……问我是否要更新,所以我说不,它卸载了旧版本的Java。 [JRE],然后我自己安装了免费的OpenJdk 12,并通过打开命令行窗口并键入“ java -version”进行了验证,得到以下输出:
C:\Users\USER>java -version
openjdk version "12" 2019-03-19
OpenJDK Runtime Environment AdoptOpenJDK (build 12+33)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 12+33, mixed mode, sharing)
因此,在此之后,我运行了上面的方法,但收到以下错误消息:
Command_List = [cmd, /c, java, -jar, C:/Dir_ProGuard/proguard6.0.3/lib/proguard.jar, @C:/Dir_Run_ProGuard/XYZ.pro, -verbose]
Error: could not open `C:\Program Files\Java\jre1.8.0_91\lib\amd64\jvm.cfg'
然后我去系统控制面板检查我的类路径,它们都没有指向jre1.8.0_91,所以我的问题是此“ jre1.8.0_91”信息保存在配置文件中的什么位置,所以我可以去那里并将其更新到我最新的JRE 12?
答案 0 :(得分:0)
一个简单的答案,但是我没有意识到,现在我重新启动Windows后,它可以正常运行。所以只需要重新启动即可!