[英]unable to open .jar executable file from another java project
There is an application inside which there are three buttons , when user clicks on the 1st the notepad exe file opens but when user clicks on the second the java .jar file doesnot open . 有一个应用程序,其中有三个按钮,当用户单击第一个时,记事本exe文件打开,但是当用户单击第二个时,java .jar文件不打开。 can someone please help following is the code i am posting
有人可以帮忙吗,以下是我发布的代码
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
//InputStreamReader isr=new InputStreamReader(System.in);
// BufferedReader br=new BufferedReader(isr);
try {
ProcessBuilder p = new ProcessBuilder();
// Use command "notepad.exe" and open the file.
p.command("java.exe", "C:\\Users\\zareeba\\Desktop\\KictCHE_UAT");
p.start();}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO add your handling code here:
}
尝试添加-jar
:
p.command("java.exe", "-jar", "C:\\Users\\zareeba\\Desktop\\KictCHE_UAT");
尝试通过添加-jar
作为参数来尝试执行此操作
p.command("java.exe", "-jar", "C:\\Users\\zareeba\\Desktop\\KictCHE_UAT.jar");
You are missing the -jar
flag. 您缺少
-jar
标志。 You need to add the -jar
flag like this: 您需要添加
-jar
标志,如下所示:
p.command("java.exe", "-jar", "C:\\Users\\zareeba\\Desktop\\KictCHE_UAT");
You can use below code to run exe file: 您可以使用以下代码运行exe文件:
try {
ProcessBuilder pb = new ProcessBuilder("cmd", "/C", "C:\\Users\\user\\Desktop\\Test.jar");
Process process = pb.start();
} catch (Exception e) {
System.out.println("e="+e);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.