How to set JVM properties (Xms and Xmx) with the Play Framework startup script

As I noted yesterday, I got a Play Framework application running on a Raspberry Pi (RPI) this weekend. Getting it running was pretty easy; I just deployed the application to a production server as usual, and on the RPI I only had to install Java, and control the RAM usage, since my old RPI doesn’t have much RAM.

When I say that I needed to control my Play application’s RAM use, I mean that I had to set the Java/JVM Xms and Xmx command line options. My Play startup script is named radio, so the command I used to start the application and control the RAM use is:

$ bin/radio -J-Xms64M -J-Xmx128M

I knew about the Xms and Xmx settings from working with Java for a long time, but what I didn’t know was that I needed to use the -J flag before those options when using the Play Framework startup script. I don’t remember doing that with earlier versions of the Play Framework, but this is necessary with Play 2.2, and presumably future Play versions.

On the Play website they also show that you can set the server JVM flag in the same way:

$ /path/to/bin/<project-name> -J-Xms128M -J-Xmx512m -J-server