Run Play dev mode from the console
Scala’s REPL is incredibly useful during development. For Play apps, especially in version 2.3 and before, much of the API requires a running application (such as WS, database access, etc). They provide a StaticApplication, but this runs in production mode. This could be an issue for configuration reasons (if there is differences in behavior, configuration, or logic between development and production).
If you try to use WS without a running application, you’ll first see: You do not have an implicit Application in scope. If you want to bring the current running Application into context, just add import play.api.Play.current. Then if you import Play.current, java.lang.RuntimeException: There is no started application.
A simple solution is to create your own ApplicationProvider that runs in dev mode.
Simple enough. In fact, it’s useful to have this available always. You can put code in a SBT setting called initialCommands to be run whenever the console is started. It’s also useful to import commonly used APIs:
Then, starting a dev mode application is as easy as typing app in the console.
We wrote this post while working on Kifi — Connecting people with knowledge. Learn more.
Originally published at eng.kifi.com on May 12, 2015.