annealer annealer

gabriel gironda will have his revenge on seattle

Zero to Compojure in a few easy steps

Written on Monday, November 23, 2009

Step One

Ensure you’re running the latest RubyGems

    gabriel@pinion:~/Code/GitHub$ sudo gem update --system
    Password:
    Updating RubyGems
    Nothing to update
    gabriel@pinion:~/Code/GitHub$ 

Step Two

Install JavaGems

    gabriel@pinion:~/Code/GitHub$ gem install javagems
    WARNING:  Installing to ~/.gem since /opt/ruby-enterprise-edition/lib/ruby/gems/1.8 and
        /opt/ruby-enterprise-edition/bin aren't both writable.
    Choosy clojurers choose Thumblemonks

    Remember to add ~/.javagem/java/bin to your PATH environment
    variable for maximum-JavaGems-fun-times.
    Successfully installed javagems-0.4.10
    1 gem installed
    Installing ri documentation for javagems-0.4.10...
    Installing RDoc documentation for javagems-0.4.10...
    gabriel@pinion:~/Code/GitHub$ 

Step Three

Install Compojure via JavaGems

    gabriel@pinion:~/Code/GitHub$ javagem install compojure
    Successfully installed clojure-1.0.0
    Successfully installed clojure-contrib-1.0.0
    Successfully installed jetty-util-6.1.22
    Successfully installed servlet-api-2.5
    Successfully installed jetty-6.1.22
    Successfully installed commons-fileupload-1.2.1
    Successfully installed commons-codec-1.4
    Successfully installed commons-io-1.4
    Successfully installed compojure-0.3.1
    9 gems installed
    Installing ri documentation for clojure-1.0.0...
    Installing ri documentation for clojure-contrib-1.0.0...
    Installing ri documentation for jetty-util-6.1.22...
    Installing ri documentation for servlet-api-2.5...
    Installing ri documentation for jetty-6.1.22...
    Installing ri documentation for commons-fileupload-1.2.1...
    Installing ri documentation for commons-codec-1.4...
    Installing ri documentation for commons-io-1.4...
    Installing ri documentation for compojure-0.3.1...
    Installing RDoc documentation for clojure-1.0.0...
    Installing RDoc documentation for clojure-contrib-1.0.0...
    Installing RDoc documentation for jetty-util-6.1.22...
    Installing RDoc documentation for servlet-api-2.5...
    Installing RDoc documentation for jetty-6.1.22...
    Installing RDoc documentation for commons-fileupload-1.2.1...
    Installing RDoc documentation for commons-codec-1.4...
    Installing RDoc documentation for commons-io-1.4...
    Installing RDoc documentation for compojure-0.3.1...
    gabriel@pinion:~/Code/GitHub$ 

Step Four

Create a new project with Compojure specified in the Gemfile

    gabriel@pinion:~/Code/GitHub$ mkdir compojure-example
    gabriel@pinion:~/Code/GitHub$ cd compojure-example/
    gabriel@pinion:~/Code/GitHub/compojure-example$ echo 'gem "compojure"' > Gemfile
    gabriel@pinion:~/Code/GitHub/compojure-example$ 

Step Five

Run your sample app

    gabriel@pinion:~/Code/GitHub/compojure-example$ cat hello.clj 
    (use 'compojure)

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

    (run-server {:port 8080}
      "/*" (servlet my-app))

    gabriel@pinion:~/Code/GitHub/compojure-example$ jam clojure.main hello.clj
    2009-11-23 20:31:35.397:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
    clojure.proxy.javax.servlet.http.HttpServlet
    2009-11-23 20:31:35.493:INFO::jetty-6.1.x
    2009-11-23 20:31:35.996:INFO::Started SocketConnector@0.0.0.0:8080

All done!

blog comments powered by Disqus

Annealer, a Jekyll powered blog by Gabriel Gironda.