Update: You can now set the run mode easy and conveniently using our sbt-runmode plugin for SBT.
run.mode in Lift applications is the source of a surprising number of questions. The documentation recommends passing it as a parameter when the JVM is invoked. This can be hard to achieve for various reasons. In our case our deployment is automated using Chef, and scripts to start and stop the Jetty web server are installed by the package manager. We don’t really want to monkey around with these scripts, so we had to find another way. Jetty is written in Java, which means it must have a ridiculously complex XML configuration language. The Jetty developers turned it up to 11 by making their configuration language Turing complete, so we can actually set the system properties in a configuration file. The file we want to create is
WEB-INF/jetty-web.xml and we want it to contain this:
If we leave this around then our application will always run in production mode. We don’t want this when we’re developing as we won’t, for instance, get stack traces printed to the browser. Thus we should copy this file in when we package up the project, and remove it when the packaging step completes. Assuming you’re using SBT, store the above text in
project/jetty-web.xml and add the following to your SBT project file to get this functionality:
This is pretty simple code. Basically it redefines the
package action to first copy in the
jetty-web.xml file, then it runs the original package action, and finally it deletes the
jetty-web.xml. Now any
WARfiles you run under Jetty will automatically be in production mode, but calling
sbt jetty-run will still give you development mode.