layout: doc title: Getting Started

The simplest way to get started with Compojure is to use Leiningen. Installing Leiningen is straightforward, and instructions to do so can be found on the Clojure Assembla Wiki.

Once Leiningen is installed, use it to create a new Clojure project:

lein new hello-www
cd hello-www

This will create a basic project skeleton we can build upon. Update project.clj in the current directory to include Compojure 0.4.0 and the Ring Jetty adapter as dependencies:

(defproject hello-www "1.0.0-SNAPSHOT"
  :description "A Compojure 'Hello World' application"
  :dependencies [[org.clojure/clojure "1.1.0"]
                 [org.clojure/clojure-contrib "1.1.0"]
                 [compojure "0.4.0"]
                 [ring/ring-jetty-adapter "0.2.3"]])

Next, use Leiningen to download the project dependencies for you:

lein deps

Now you're ready to write the application. Put the following code into src/hello-www/core.clj:

(ns hello-www.core
  (:use compojure.core
        ring.adapter.jetty)
  (:require [compojure.route :as route]))

(defroutes example
  (GET "/" [] "

Hello World Wide Web!

") (route/not-found "Page not found")) (run-jetty example {:port 8080})

To run this application, use:

lein repl src/hello-www/core.clj

Visit http://localhost:8080 to see the results. If all has gone well, you'll see your "Hello World" page.