Justin Lei
Justin Lei

Reputation: 23

How to properly exit standalone Java Play Framework script?

I am using Java Play Framework 2.3.7 and have a standalone script that uses StaticApplication and imports stuff into my database that I want am able to run manually using the runMain command.

Mostly, it works pretty well, but I can't figure out how to make it exit properly. If I try using a System.exit(0);, it returns this error message:

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

If I leave out the System.exit(0), I have to kill the process using Ctrl+C myself.

Anybody know what to do? Thanks!

Upvotes: 2

Views: 1385

Answers (1)

Michael Zajac
Michael Zajac

Reputation: 55569

When running a StaticApplication (or any Application) in Play, you can stop the Application that is currently running (there can only be one) by using:

play.api.Play.stop()

The Play object keeps a reference to the current running application, and calling stop() will shut it down by stopping all of its running plugins.

Upvotes: 1

Related Questions