title: Java how to run another .jar program from code in response to button click
body: <p>I have written a Java program that should open another program (which is a .jar file). If I use this code in the main class of my program, all works correctly:</p>
  
  <pre><code>File logFile = new File("./ePaymentUpdater.jar");
  Desktop.getDesktop().open(logFile.getCanonicalFile());
  //or
  Runtime.getRuntime().exec("java -jar ePaymentUpdater.jar");
  </code></pre>
  
  <p>But if I paste the same code in the event in response to the user clicking a button, it doesn't work as it should:
  The program seems to run, because it creates a folder like it should be (this code is in the main class of the called program), but it doesn't show the jFrame it should</p>
  
  <p>It seems that i cannot open a frame from inside the frame of another program...</p>
  
  <p>This is my main class:</p>
  
  <pre><code>package prove_idiote;
  import java.awt.Desktop;
  import java.io.File;
  import javax.swing.JOptionPane;
  
  public class Main {
  
      public static void main(String[] args) {  
  
  //        try {
  //            Runtime.getRuntime().exec("java -jar ePaymentUpdater.jar");
  //        } catch (Exception e) {            
  //            System.out.println(e);
  //        }
  
          Tester tester = new Tester();
          tester.setVisible(true);       
      }   
  }
  </code></pre>
  
  <p>And this is my button event:</p>
  
  <pre><code>private void ExecuteActionPerformed(java.awt.event.ActionEvent evt) {                                         
      try {
  
          JOptionPane.showMessageDialog(null, "before" ,"ATTENZIONE!",JOptionPane.WARNING_MESSAGE);
  
          Runtime.getRuntime().exec("java -jar ePaymentUpdater.jar");
  
          JOptionPane.showMessageDialog(null, "after" ,"ATTENZIONE!",JOptionPane.WARNING_MESSAGE);
  
      } catch (Exception e) {            
          System.out.println(e);
      }
  } 
  </code></pre>