gpt4 book ai didi

java - 如何正确退出独立的 Java Play Framework 脚本?

转载 作者:行者123 更新时间:2023-11-30 11:10:45 24 4
gpt4 key购买 nike

我正在使用 Java Play Framework 2.3.7 并有一个独立脚本,该脚本使用 StaticApplication 并将我希望能够使用 runMain 手动运行的内容导入我的数据库> 命令。

大多数情况下,它工作得很好,但我不知道如何让它正确退出。如果我尝试使用 System.exit(0);,它会返回此错误消息:

Exception: sbt.TrapExitSecurityException thrown from the UncaughtExceptionHandler in thread "run-main-0"

如果我遗漏了 System.exit(0),我必须自己使用 Ctrl+C 终止进程。

有人知道怎么办吗?谢谢!

最佳答案

在 Play 中运行 StaticApplication(或任何 Application)时,您可以停止当前正在运行的 Application(只能有一)通过使用:

play.api.Play.stop()

Play 对象保留对当前正在运行的应用程序的引用,调用 stop() 将通过停止所有正在运行的插件来关闭它。

关于java - 如何正确退出独立的 Java Play Framework 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27610125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com