How to Run Jetty Example with Ring in Clojure -


i following along this example on creating simple web service in clojure using ring , jetty.

i have in 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"]]) 

this in script/run.clj

(use 'ring.adapter.jetty) (require '[ws-example.web :as web])  (run-jetty #'web/app {:port 8080}) 

and in 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)) 

however, when execute:

lein run script/run.clj 

i error:

no :main namespace specified in project.clj. 

why getting , how fix it?

you're getting error because purpose of lein run (according lein run) "run project's -main function." don't have -main function in ws-example.web namespace, nor have :main specified in project.clj file, lein run complaining about.

to fix this, have few options. move run-jetty code new -main function of ws-example.web function , lein run -m ws-example.web. or , add line :main ws-example.web project.clj , lein run. or try using lein exec plugin execute file, rather namespace.

for more info, check out leiningen tutorial.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -