I was just playing around a bit with the Ring library for Clojure and wanted to be able to use it from within Emacs/Slime. Getting Jetty to start is actually really easy: You just start it like they do in the examples that come with Ring.

Reloading upon recompile (using C-c C-c), however, did not work out of the box. Jetty continued to use the old version of whatever Ring fed it (a Servlet, I suppose). Now Ring has this concept of a middleware, which is basically a function that wraps your own function and performs some magic before calling that. One of the included middlewares is “reload”, which, on every request, reloads a set of namespaces you pass it. This did not work for me. It always complained about not being able to find the namespace I passed it and the documentation actually clearly states that it would only work with .clj-files, not with jars or compiled classes. What did work, however, was something much simpler:

(defn app [req] ...)

(defn reloader [req]
  (app req))

;; now call jetty.run and pass it reloader as the app

Now when you make a change to app and hit C-c C-c to compile it, refreshing the page should execute your new code. My guess is that this works because Ring creates a Servlet class using the function you pass it which then gets passed to Jetty. When you recompile your function, that class stays the same. The function that gets passed will, however, be aware of the environment around it. So when you (by recompiling) change the definition of “app”, “reloader” will use that from then on.