Can I use an install4j launcher to restart a java application?

让人想犯罪 __ 提交于 2019-12-12 17:08:41

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/10981152/can-i-use-an-install4j-launcher-to-restart-a-java-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!