0

I want to open JAR file by pressing JButton in JPanel. To achieve this goal I used ActionListener with ProcessBuilder inside. Here is my code:

myButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
    ProcessBuilder pb = new ProcessBuilder("java", "-jar"
           , "f:/Documents/TBot/topbotclient.jar"
           , "-n", getTopBotName().getText()
           , "-pw", getTopBotPass().getText()
           , "-s", getScript_name().getText()
           , "-w", getWorld().getText()
         );
    try {
        Process p = pb.start();
    } catch (IOException ee) {
        ee.printStackTrace();
    }

        }
    });

The problem is that opened JAR file do not function properly - it freezes after I press some of its buttons. However, if I close my initial JAVA window that is used to open external JAR, JAR file becomes functional again. What to do to get both initial window and opened JAR file window functional?

I did not find any solution by searching: Run a jar File from java program, Execute .jar file from a Java program etc.

UPDATE:

I tried not to use ProcessBuilder and used "runtime.exec" instead.

try {
    Runtime runtime = Runtime.getRuntime();
    runtime.exec(" java -jar f:/Documents/TBot/scripts/topbot.jar -n Fataho -pw diehard15 -s scriptjoiner -w 301 -nort -a b@hadas.lt -apw blood444");
} catch (Exception ex) {
    JOptionPane.showMessageDialog(null, "Exception occured" + ex);
}

The problem remains the same.

Community
  • 1
  • 1
Fataho
  • 99
  • 3
  • 15
  • Does the other program do anything with `System.in`, `System.out` or `System.err`? – RealSkeptic Nov 07 '15 at 17:10
  • I tried to find out, but I failed. I do not know does second program (JAR file that I want to open) has anything to do with System.in, System.out or System.err. I use this program that can be downloaded here https://topbot.org/ – Fataho Nov 07 '15 at 18:13

1 Answers1

0

Try to start a processbuilder in a separate thread so that your main thread won't block. From your code your doing everything in a Main thread. Make use of swingWorker kind of stuff to start the operation in a separate thread.

Shriram
  • 4,343
  • 8
  • 37
  • 64
  • Why do you think it's blocking? There is no call to `waitFor()`. Also, the OP says the secondary program is the one that freezes. – RealSkeptic Nov 07 '15 at 17:13
  • I tried using new Thread(new Runnable() {..., It did not help. The problem remains the same. – Fataho Nov 07 '15 at 19:04