I set the development mode in the scalatra servlet to a config/system property value
object AppEnv {
private val cloader = getClass.getClassLoader
val PRODUCTION = "production".intern
val DEVELOPMENT = "development".intern
val STAGING = "staging".intern
val TEST = "test".intern
lazy val environment = readEnvironmentKey(println _)
def isProduction = isEnvironment(PRODUCTION)
def isDevelopment = isEnvironment(DEVELOPMENT)
def isStaging = isEnvironment(STAGING)
def isTest = isEnvironment(TEST)
def isEnvironment(env: String) = environment.toLowerCase(Locale.ENGLISH) == env.toLowerCase(Locale.ENGLISH)
def readEnvironmentKey(failWith: String ⇒ Unit = _ ⇒ null) = {
(ep("BACKCHAT_MODE") orElse sp("backchat.mode")) getOrElse {
val inferred = "development"
failWith("no environment found, defaulting to: " + inferred)
inferred
}
}
private def sp(key: String) = {
val s = System.getProperty(key)
if (s != null && s.trim.nonEmpty) Some(s) else None
}
private def ep(key: String) = {
val s = System.getenv(key)
if (s != null && s.trim.nonEmpty) Some(s) else None
}
}
trait ApplicationModes extends ScalatraKernel {
override def environment: String = AppEnv.environment
override def isDevelopmentMode = environment != AppEnv.PRODUCTION && environment != AppEnv.STAGING
}
Scalatra also allows you to use System property to set that mode, you can possibly read that property out and get similar results. -Dorg.scalatra.environment=development