Getting Compojure Working On Windows 7

It’s a lot easier to do decent installation documentation on a clean computer.  Today I tried building Clojure and Compojure from scratch.  First you need to be able to run powershell scripts.  If you can’t, do the following

  • Close all powershell windows
  • Start a powershell window as administrator
  • set-executionpolicy Unrestricted

(I’m assuming that if you have more sophisticated security requirements, you’ll know enough to implement them yourself.)

Building Clojure

I’m going to assume that everything gets built into a directory I’m calling D:OSS.

First, download the following simultaneously:

  • MSysGit.  I used the net install.  Try something like D:OSSMSysGit as the installation directory
  • At the same time, download and install the latest JDK.  Windows 7 64-bit uses the x64 version.
  • Download Ant and unpack it into d:ossant

Once git is installed, create a file git-powershell.bat in the installed directory with the following content:  (Note the explicit setting of JAVA_HOME: if you don’t do this, ant will try using the JRE, which won’t work.)

    @set PLINK_PROTOCOL=ssh
    @for /F “delims=” %%I in (“%~dp0”) do @set git_install_root=%%~fI
    @set path=%git_install_root%bin;%git_install_root%mingwbin;%git_install_root%cmd;%git_install_root..antbin;%%PATH%
    @if “%HOME%”==”” @set HOME=%USERPROFILE%
    @cd %HOME%
    @set JAVA_HOME=C:Program FilesJavajdk1.6.0_20

This file is going to be your standard way of running your dev command line.  Click on it to get running and switch to the OSS directory.  Then type

git clone git://
cd clojure

Building Compojure

Now get the lein ps1 script from GitHub and put it on your path.  Call it lein.ps1.  Then type*

cd ..
git clone git://
cd compojure
lein self-install
lein deps
lein jar

Running Hello World

We’re still not finished.  We’re going to need a script to run compojure:

$compojureDirectory = (split-path $MyInvocation.MyCommand.Path)
$jars = (ls (join-path $compojureDirectory *.jar),(join-path $compojureDirectory lib*.jar))
$classPath = [String]::Join(“;”, $jars)  # Create a class path with compojure and every jar in libs on it
$script = (join-path $pwd.Path $args[0])
java -cp $classPath clojure.main -i $script -r $args

Put that in compojure.ps1.  Now we finally try getting started with Compojure.

Create a file hello.clj

(ns hello-world
  (:use compojure.core ring.adapter.jetty))

(defroutes routes
  (GET “/” []
    “<h1>Hello World</h1>”)
  (ANY “*” []
    {:status 404, :body “<h1>Page not found</h1>”}))

(run-jetty routes
    {:port 8080})

You can theoretically put this anywhere you like, but put it in the Compojure directory for now.  Now type “.compojure.ps1 hello.clj” and your web server should start.  Navigate to http://localhost:8080/ and you should see:

Hello World

If you’re thinking apt-get was easier, you’d be right.

*The instructions get Compojure working, but not against the trunk Clojure.  For that, you’ll need to copy the jar file around after lein deps.

UPDATE: The original lein.ps1 script worked as for as these instructions were concerned, but failed in a number of hard-to-debug ways.  As a consequence, I’ve updated it and merged it with lein.bat, which works but involves source hacking the whole time to get it to work.  Hopefully the new version will be the best of both worlds.

Technorati Tags: ,,

Published by

Julian Birch

Full time dad, does a bit of coding on the side.

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 )

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