[英]Java cannot run Exec Jar using ProcessBuilder
I am running these line of codes to run a Test.jar which is an executable jar 我正在运行这些代码行来运行Test.jar,这是一个可执行的jar
public static void main(String[] args) throws IOException{
File f = new File("path to exe jar");
if(f.exists() && !f.isDirectory()) {
System.out.println("Valid");
}else{
System.out.println("Invalid");
}
ProcessBuilder pb =
new ProcessBuilder("path to exec jar", "-jar", "Test.jar",
"args1","args2","args3","args4");
pb.directory(new File("path to exec jar"));
Process p = pb.start();
}
And I keep getting this error: File is valid though so I think this might be access issues. 而且我一直收到此错误:文件仍然有效,所以我认为这可能是访问问题。 What do I need to add to get the access needed? 我需要添加什么才能获得所需的访问权限?
Valid
Exception in thread "main" java.io.IOException: Cannot run program "abc" (in directory "abc"): CreateProcess error=5, Access is denied
"path to exe jar"
should be "java"
in the constructor for ProcessBuilder
. 在ProcessBuilder
的构造函数中, "java"
"path to exe jar"
应为"java"
。 You can't execute a path. 您无法执行路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.