Farheen
Farheen

Reputation: 9

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 . 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

Answers (4)

Rafiq
Rafiq

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

Aditya Singh
Aditya Singh

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

user377628
user377628

Reputation:

Try to add -jar:

p.command("java.exe", "-jar", "C:\\Users\\zareeba\\Desktop\\KictCHE_UAT");

Upvotes: 2

Related Questions