Reputation: 33
I need to restart a java GUI application in response to a user action, in a similar way to eclipse restarting itself when you switch workspaces.
We currently use an install4j launcher, so I'm wondering if the launcher can be configured to stay running and to restart the application if I exit the application with a particular return code or something like that?
Cheers
Upvotes: 3
Views: 1220
Reputation: 5808
Make sure to configure the executable name.
Otherwise it will just fail silently: The installer compilation and the launchApplication()
call will not throw any errors. And without any error messages or log files to look at, this took me a day of trial & error to figure out.
Also, it is possible to set a custom ID to avoid cryptic application IDs:
ApplicationLauncher.launchApplication("restarter", new String[] { "-q", "-wait", "20", "-splash", "Restarting..." }, /* blocking */ false, /* callback */ null);
Upvotes: 1
Reputation: 48035
This is not a feature in install4j. However, you can just start the launcher again by using java.lang.ProcessBuilder and call System.exit().
If the launcher is a single instance GUI launcher, you have to use another executable that waits for the launcher to shut down and then restarts the original executable. This can be done easily with a custom installer application that contains an "Execute launcher" action in its "Startup" node. The custom installer application is launched via the API with the arguments
-q -wait 20
i.e. it is executed in unattended mode (no GUI) and waits for a maximum of 20 seconds for all installed launchers to shut down. To show a progress bar, add
-splash "Restarting application"
to the arguments. The code to launch the custom installer application looks like this:
import java.io.IOException;
import com.install4j.api.launcher.ApplicationLauncher;
try {
ApplicationLauncher.launchApplication("ID", new String[] {
"-q","-wait","20"
}, false, null);
} catch (IOException e) {
e.printStackTrace();
//TODO handle invocation failure
}
where ID has to be replaced with the ID of the custom installer application.
Upvotes: 6