Compojure + Maven

July 30, 2009

Update: Chas Emerick has written a much more accurate, up-to-date and comprehensive guide.

Being a terse guide to getting mavenic web app development with compojure. The code is available at

1. Download, build and install clojure-contrib

git clone git://
cd clojure-contrib
mvn install -DpomFile=pom.xml -Dfile=clojure-contrib.jar

2. Download, build and install compojure

git clone git://
cd compojure
ant deps
mvn install:install-file -DgroupId=org.clojure -DartifactId=compojure \
-Dversion=1.0-SNAPSHOT -Dfile=compojure.jar -Dpackaging=jar

3. Create your Compojure app

In src/main/clj/example/MyApp.clj:

;; MyApp
(ns example.MyApp
  (:use compojure)
    :extends javax.servlet.http.HttpServlet))

;; Router
(defroutes my-app
  (GET "/" (html [:h1 "Hello World!"]))
  (ANY "*" (page-not-found)))

(defservice my-app)

4. Get Maven to compile your servlet

In pom.xml in the build section:







5. Make sure your clojure files get copied on to the file path

In pom.xml in the build section:


6. Configure the jetty plugin

Again, in the build section of pom.xml:






7. Fix up the rest of the dependencies and the rest of the mvn stuff

The usual boilerplate – grab it from bitbucket:

8. GO!

mvn jetty:run

Will run your application up on a localhost server, and any mods to the clojure will trigger an application redeployment. Ace!


7 Responses to “Compojure + Maven”

  1. Wow – thanks for the concise info. You didn’t mention about web.xml but thankfully it is in your source 🙂

  2. Chas Emerick Says:

    Thanks for the pointer — the configuration of the jetty plugin only needed a little tweak to get this working for me. Looks like comments with URLs are being blocked right now, so go to if you’re interested.

    Thanks again!

  3. chetan Says:

    Just curious, why not just use leiningen (
    It hides & wraps the maven ugliness

  4. jimdowning Says:

    @chetan A few reasons: –

    1/ At the moment leiningen isn’t doing everything maven gives me (even in this brief example).

    2/ I’m not too keen on the leiningen’s default dependency building mechanism of copying jars to lib (although I can see that having this facility would be useful in some circumstances)

    3/ We’ve got a lot of other maven projects and a build environment (CI, nexus etc) that works well with maven. A move to leiningen would likely be a lot of hassle for a bit of neat syntax!

  5. MelWinkelk Says:

    Thanks for this tutorial! This saved a lot of time.

    IMHO it’s better to replace the maven-exec-plugin with
    the clojure-maven-plugin ( for clojure compilation. Less config, more flexibility.




  6. jimdowning Says:

    @MelWinkelk I agree – this is out of date – better to use the clojure-maven-plugin these days.

  7. […] came across this post by Jim Downing, which describes how to set up a Maven project for a Compojure application, enabling […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: