Gangmax Blog

自由之思想,独立之精神

Run Http-kit in Lein

| Comments

After creating a clojure project(by running “lein new my-sandbox”), modify the “project.clj” file:

1
2
3
4
5
6
7
8
9
; Line 8 is added manually to add the "http-kit" dependency
(defproject my-sandbox "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [http-kit "2.1.18"]
                ])

Then get into the “my-sanbox” directory and run “lein repl”:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
user=> (println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))
(#<URL file:/home/user/temp/lein/my-sandbox/test/> #<URL file:/home/user/temp/lein/my-sandbox/src/> #<URL file:/home/user/temp/lein/my-sandbox/dev-resources> #<URL file:/home/user/temp/lein/my-sandbox/resources/> #<URL file:/home/user/temp/lein/my-sandbox/target/classes/> #<URL file:/home/user/.m2/repository/clojure-complete/clojure-complete/0.2.3/clojure-complete-0.2.3.jar> #<URL file:/home/user/.m2/repository/org/clojure/tools.nrepl/0.2.3/tools.nrepl-0.2.3.jar> #<URL file:/home/user/.m2/repository/http-kit/http-kit/2.1.18/http-kit-2.1.18.jar> #<URL file:/home/user/.m2/repository/org/clojure/clojure/1.5.1/clojure-1.5.1.jar>)
nil
user=> (require '[org.httpkit.server :as server] :verbose)
(clojure.core/in-ns 'user)
(clojure.core/alias 'server 'org.httpkit.server)
nil
user=> (defn app [req]
  #_=>   {:status  200
  #_=>    :headers {"Content-Type" "text/html"}
  #_=>    :body    "hello HTTP!"})
#'user/app
user=> (server/run-server app {:port 8000})
#< clojure.lang.AFunction$1@2087ecb>

Comments