我正在關注使用ring和jetty在Clojure中創建簡單Web服務的this example。如何在Clojure中使用Ring運行Jetty示例
我有這個在我的project.clj:
(defproject ws-example "0.0.1"
:description "REST datastore interface."
:dependencies
[[org.clojure/clojure "1.5.1"]
[ring/ring-jetty-adapter "0.2.5"]
[ring-json-params "0.1.0"]
[compojure "0.4.0"]
[clj-json "0.5.3"]]
:dev-dependencies
[[lein-run "1.0.0-SNAPSHOT"]])
這在腳本/ run.clj
(use 'ring.adapter.jetty)
(require '[ws-example.web :as web])
(run-jetty #'web/app {:port 8080})
這將src/ws_example/web.clj
(ns ws-example.web
(:use compojure.core)
(:use ring.middleware.json-params)
(:require [clj-json.core :as json]))
(defn json-response [data & [status]]
{:status (or status 200)
:headers {"Content-Type" "application/json"}
:body (json/generate-string data)})
(defroutes handler
(GET "/" []
(json-response {"hello" "world"}))
(PUT "/" [name]
(json-response {"hello" name})))
(def app
(-> handler
wrap-json-params))
但是,當我執行時:
lein run script/run.clj
我得到這個錯誤:
No :main namespace specified in project.clj.
爲什麼會出現這個?如何解決?
您鏈接的教程使用Leiningen 1.x - 您應該使用lein2。 – Alex 2013-04-05 17:29:44
如果我能找到一個自從學習以來就能工作的教程,那將是非常棒的。有什麼建議麼?我想在Clojure – 2013-04-05 17:33:38