Since release 1127, you can now do this instead:
$ cat src/mypkg/HelloServlet.clj
(ns myapp.HelloServlet
(:gen-class
:extends javax.servlet.http.HttpServlet)
(:import (
java.io PrintWriter)
(java.util.logging Logger Level))
(:require swank clojure.main))
(defn- -init [this config]
(clojure.main/with-bindings
(swank/ignore-protocol-version "2008-11-23")
(swank/start-server "/dev/null" :port 4006 :encoding "iso-latin-1-
unix")))
(defn- -doGet [this request response]
(.severe (Logger/getLogger "hello") "logging this thang")
(.setContentType response "text/html")
(let [out (PrintWriter. (.getWriter response))]
(doto out
(.println "<html>")
(.println "<head>")
(.println "<title>Hello World!</title>")
(.println "</head>")
(.println "<body>")
(.println "<h1>Hello Bizarro World...from Clojure!</h1>")
(.println (str "17 + 33 = " (+ 17 33)))
(.println "</body>")
(.println "</html>"))))
It doesn't handle the unloading/reloading of servlets well, so it
could be improved by:
1. Letting swank pick which port to listen on, and writing the port
number to a temporary file.
2. On unload, closing the swank socket and deleting the temporary
file.
I posted the whole project (build.xml, etc...) here:
http://paste.lisp.org/display/71326
I'm also going to try installing a Compojure-built servlet into
Tomcat. I'll post that later if I can make that work.