Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oscarrenalias/2215134 to your computer and use it in GitHub Desktop.
Save oscarrenalias/2215134 to your computer and use it in GitHub Desktop.
Play Scala snippets
//
// How to start the embedded H2 web server in a Play Scala application
//
org.h2.tools.Server.startWebServer(play.api.db.DB.getConnection()(play.api.Play.current))
// the browser should automatically open but if not, the correct URL is http://192.168.255.11:58024/
// alternatively, this code only starts the web server (and the connection data must be manually provided). The
// correct port is 8082
org.h2.tools.Server.createWebServer("").start
//
// Alternative way to start a Play application from the console
//
play.api.db.evolutions.OfflineEvolutions.applyScript(new java.io.File("."),this.getClass.getClassLoader,"default")
val a = new play.core.StaticApplication(new java.io.File("."))
// Usage:
// Run `play console` and then :paste the below code
//
// Tested on commit 4727620693 of Play20 master, at Feb 6.
// Fixed by Oscar Renalias/phunkphorce for Play 2.0 final
//
// Follow the below steps to enable play.api.test classes in Play console.
// $ set libraryDependencies += "play" %% "play-test" % "2.0"
// $ console
import play.api.Application
import play.api.Play
import play.api.db.evolutions.OfflineEvolutions
import play.api.Mode
OfflineEvolutions.applyScript(new java.io.File("."), Thread.currentThread.getContextClassLoader, "default")
val application = new Application(new java.io.File("."), Thread.currentThread.getContextClassLoader, None, Mode.Dev)
Play.start(application)
import play.api.Play.current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment