The Heroku blog has a good description on running Clojure but let’s do it ourselves.

This is very similar to the previous post Running Clojure on the AWS Beanstalk

A Hello World web app

The source is on

We’re assuming that you have lein and Java installed and that you’ve installed the tools from

We’ll use to build the app. First the app itself.

(ns ctdean.heroku.hello
  (:use noir.core hiccup.core)
  (:require [noir.server :as server]))

;; The only page
(defpage "/" []
  "<html><body>Hello world</body></html>")

;; The entry point for Heroku
(defn -main [& m]
  (let [mode (keyword (or (first m) :dev))
        port (Integer. (get (System/getenv) "PORT" "5000"))]
    (server/start port {:mode mode
                        :ns 'ctdean.heroku.hello})))

The equally important project.clj

(defproject ctdean-heroku-hello "1.0.0"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [noir "1.2.2"]]
  :main ctdean.heroku.hello)

And the Procfile that Heroku uses.

web: lein run -m ctdean.heroku.hello

Let’s try it out:

% foreman start &

You can look at it in your browser at http://localhost:5000, or on the command line:

% curl http://localhost:5000
<html><body>Hello world</body></html>

Push out the app

Heroku uses git to push out the code so we need to create the git repo:

% git init .
% echo target >.gitignore
% git add Procfile project.clj .gitignore src/ test/
% git commit -m 'Initial checkin'

and then we create the Heroku app:

% heroku create --stack cedar

When the app is created it will assign a default url, in my case it was

And then push it out:

% git push heroku master

View the app

The app should now be running on the assigned url. You can view it in your browser using the

% heroku apps:open

11 Apr 2012

Previous Archive Next