Faster turnaround with xsbt-web-plugin

January 29, 2017

Quick, start!

The 2.3.0 release of xsbt-web-plugin introduced the quickstart command, which speeds up the container bootstrapping process by serving directly from a project's static resources and compiled classes.

$ sbt
> jetty:quickstart

Not only does this skip the preparation and packaging of a .war file, but it also allows the container to serve changes the developer makes to static resources without recompiling any code and without restarting the server.

Reloading code changes instantly

We can take this a step further. Serving changes to source code still requires restarting the server, since its JVM process won't know about changes to compiled classes. We can get around this by using JRebel to reload changes directly in our container's JVM process.

All we need to do is include in build.sbt an -agentpath argument pointing to the JRebel library when we launch the container JVM:

javaOptions in Jetty += "-agentpath:/path/to/jrebel/lib/"

Optionally, extract the JRebel path to an environment variable, use sys.env:

javaOptions in Jetty += s"""-agentpath:${sys.env("JREBEL")}/lib/"""

Now, when we launch our container using quickstart, we can re-issue the compile command to see changes to source code deployed instantly, with no need to restart the server.

$ sbt
> jetty:quickstart
> ~compile

Here's how the workflow looks on my (eight-year-old) laptop:

quickstart screencast
quickstart screencast

Installing JRebel

  1. Download and extract JRebel "standalone"

  2. If you don't already have a license, request an evaluation license, then check your email inbox for a jrebel.lic attachment

  3. Activate JRebel using your license

    $ /path/to/jrebel/bin/ /path/to/jrebel.lic