我想从我的java代码运行一个jar文件。我见过很多方法,但都没有奏效。
try {
File myFile = new File("C:\\Users\\Shayan pc\\Desktop\\AutomatedGameTesting-master\\AutomatedGameTesting-master\\Mario Side-Scroller(Game)\\mario.jar");
if(myFile.exists()){
System.out.println("file found");
}
Desktop.getDesktop().open(myFile);
} catch (IOException ex) {
}这种方法也不起作用。任何帮助都将不胜感激。
发布于 2016-09-09 23:39:55
Process p = Runtime.getRuntime()
.exec("cmd /c start cmd.exe /K \"cd.. && cd Mario Side-Scroller(Game) && java -jar mario.jar\"");好的,这就完成了
发布于 2016-09-09 10:52:41
您可以尝试这样做:
Process p = Runtime.getRuntime().exec("java -jar \"your path to jar file\"");备注必须有\“字符
https://stackoverflow.com/questions/39400367
复制相似问题