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.