6

この例では、リングとジェッティを使用して Clojure で単純な Web サービスを作成しています。

私は私の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"]])

これはscript/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.

これが発生する理由と修正方法を教えてください。

4

3 に答える 3

2

(run-jetty)そのようなものを-mainどこかに入れてから、project.clj好きなものに追加する必要があります

:main ws-example.core)
于 2013-04-05T16:34:51.000 に答える
0

からlein help run:

USAGE: lein run -m NAMESPACE[/MAIN_FUNCTION] [ARGS...]
Calls the main function in the specified namespace.

そのためscript.clj、プロジェクトのソース パスのどこかに配置して、次のように呼び出す必要があります。

lein run -m script
于 2013-04-05T17:27:22.187 に答える