Reputation: 9
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 . 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:
}
Upvotes: 0
Views: 56
Reputation: 750
You can use below code to run exe file:
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);
}
Upvotes: 0
Reputation: 2453
You are missing the -jar
flag. You need to add the -jar
flag like this:
p.command("java.exe", "-jar", "C:\\Users\\zareeba\\Desktop\\KictCHE_UAT");
Upvotes: 0
Reputation: 1665
Try doing this by adding -jar
also as argument
p.command("java.exe", "-jar", "C:\\Users\\zareeba\\Desktop\\KictCHE_UAT.jar");
Upvotes: 1
Reputation:
Try to add -jar
:
p.command("java.exe", "-jar", "C:\\Users\\zareeba\\Desktop\\KictCHE_UAT");
Upvotes: 2