在JavaFx中重新启动应用程序 [英] Restart an Application in JavaFx

查看:999
本文介绍了在JavaFx中重新启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想关闭然后重新启动已经运行的应用程序(自动),通过单击按钮或类似的东西,我想这样做是为了以其他语言重新启动应用程序,我是JavaFx和Java的新手,请问你能给我一个解决这个问题的方法吗?

I want to close and then restart a already running application (automatically) that I am making, by clicking a button or something like that, I want to do that for the purpose of re-launching the application in an other language, I'm new to JavaFx and Java in general, please can you give me a solution for this problem ?

推荐答案

这个问题缺乏细节。您确实提到了JavaFX应用程序,但了解该应用程序的部署方式非常重要。它是作为Java webstart应用程序,独立jar还是独立的本机应用程序在Web浏览器中运行的?你是如何开始申请的?对这些问题的回答将使您更容易回答具体问题。

This question lacks details. You did mention a JavaFX application but it is important to know how that application is being deployed. Is it running in the web browser, as a java webstart application, a stand-alone jar, or a self-contained native application? How are you starting the application to begin with? Having the answer to these questions will make it easier to answer your question with specifics.

虽然以下示例不是JavaFX,但此处使用的方法适用于某些可以部署JavaFX应用程序的方式。重新启动运行良好的应用程序的一种方法是从脚本启动应用程序。在脚本内部将是一个while循环,它根据程序退出代码不断重新启动程序。以下是在Linux平台上启动IntelliJ的bash shell脚本的示例:

While the following example is not JavaFX, the approach used here would work for some of the ways in which a JavaFX application can be deployed. One approach for restarting an application that works nicely is to start the application from a script. Inside the script would be a while loop that continually restarts the program based on the program exit code. Here is an example for a bash shell script which starts IntelliJ on a Linux platform:

while true ; do
   eval "$JDK/bin/java" $ALL_JVM_ARGS -Djb.restart.code=88 $MAIN_CLASS_NAME $*
   test $? -ne 88 && break
done

在这个例子中,启动脚本正在传递jb.restart.code 作为应用参数。如果IntelliJ希望重新启动,它将返回该值88作为退出代码。脚本会观察应用程序退出代码,如果值为88,则重新启动应用程序。

In this example, the startup script is passing "jb.restart.code" as an application parameter. If IntelliJ wishes to restart, it will return that value 88 as the exit code. The script observes the application exit code, and restarts the application if the value is 88.

这种方法适用于大多数平台,但要求应用程序通过脚本。

This approach works well on most platforms, but requires the application to be initiated via a script.

这篇关于在JavaFx中重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆