我可以使用install4j启动器重新启动Java应用程序吗?
我需要重新启动Java GUI应用程序以响应用户操作,这类似于在切换工作区时自动重新启动自身.
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.
我们当前使用的是install4j启动器,所以我想知道是否可以将启动器配置为保持运行并重新启动应用程序(如果我使用特定的返回码或类似的代码退出应用程序)?
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?
欢呼
这不是install4j的功能.但是,您可以使用java.lang.ProcessBuilder再次启动启动器,然后调用System.exit().
This is not a feature in install4j. However, you can just start the launcher again by using java.lang.ProcessBuilder and call System.exit().
如果启动器是单实例GUI启动器,则必须使用另一个可执行文件,等待启动器关闭然后重新启动原始可执行文件.这可以通过自定义安装程序轻松完成,该程序在其启动"节点中包含执行启动器"操作.定制安装程序通过带有参数的API启动
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
即它以无人参与模式(无GUI)执行,最多等待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
}
其中的ID必须替换为自定义安装程序应用程序的ID.
where ID has to be replaced with the ID of the custom installer application.