I created a console application using Java, then exported it as runnable JAR file. but when I run the JAR file the automation is finished but the "Java (TM) Platform SE binary" is still on background, I tried to put System.exit(0)
and still not able to terminate the process.
I'm also trying to run this automatically in Task Scheduler in indefinitely repetition every 15 minutes, the problem is it will not run again after 15 minutes since the "Java (TM) Platform SE binary" is still in process and identified its status as running.
I'm pretty sure that all my automation task is all finished without error and not creating another threads.
Here is my code below:
public static void main(String[] args) {
String jarName = new File(Selenium.class.getProtectionDomain().getCodeSource().getLocation().getPath())
.getName();
System.out.println("Running " + jarName + " Automation");
if (args.length >= 1 && args[0].toLowerCase().equals("-run")) {
for (int i = 1; i < args.length; i++) {
String pram = args[i].replace(jarName + "_", "");
if (pram.toLowerCase().equals("all")) {
GFC.execute("Login");
GFC.execute("SwitchIntegration");
GFC.execute("BODActivate");
GFC.execute("Users");
GFC.execute("Settings");
GFC.execute("AccountingEntityRegistration");
GFC.execute("CustomizedData");
GFC.execute("BOD");
GFC.execute("BODAttributesMDM");
GFC.execute("BODAttributesTransactional");
GFC.execute("CMD");
GFC.execute("CMDAttributes");
GFC.execute("CMDDataEntry");
GFC.execute("CMDActivate");
GFC.execute("AccountingEntity");
GFC.execute("AccountingEntityMapping");
GFC.execute("JETemplates");
GFC.execute("Scenarios");
GFC.execute("Rules");
GFC.execute("RulesScript").quit();
} else {
if (!pram.equals("Login")) {
GFC.execute("Login");
}
GFC.execute(pram).quit();
}
}
if (Boolean.parseBoolean(infor.automation.utils.Properties.get("gfc.enableemailer"))) {
sendEmail();
}
}
}
Update: 3/14/2018
I make a workaround or maybe a solution. I found out that the System.exit(0)
on main will only close the console application, but the "Java (TM) Platform SE binary" will remain. To terminate this I extended to JFrame
class to be able to override the ExitApp()
. Inside the ExitApp()
I add window listener and in windowClosing()
I called the disposed()
and System.exit(0)
once more. I don't have any idea how this even works. If someone know how this works feel free to update this answer.
public class TestClass extends JFrame {
public void ExitApp() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// Dispose Java (TM) Platform SE binary.
dispose();
// Close the Java.exe I'm not sure.
System.exit(0);
}
});
}
public static void main(String[] args) {
// Close Your Application Trigger ExitApp();
System.exit(0);
}
}