我对Clojure、leiningen和Java工具链都不熟悉(但对Lisp、函数式编程和软件有一定了解)。我正在尝试在Compojure中引导一些RESTful Web服务。
按照指南,我很容易开始使用compojure。
https://github.com/weavejester/compojure/wiki/Getting-Started
我现在正在尝试逐步添加来自已过时的网站的功能。
http://mmcgrana.github.com/2010/08/clojure-rest-api.html
从上面第一个链接提供的使用leiningen
构建的工作项目开始(可以通过lein ring start
启动),我只需在project.clj文件中添加一行代码。
(defproject hello-world "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.4.0"]
[ring-json-params "0.1.3"] ;;; <---===/// Here's the line I added
[compojure "1.1.5"]]
:plugins [[lein-ring "0.8.2"]]
:ring {:handler hello-world.handler/app}
:profiles
{:dev {:dependencies [[ring-mock "0.1.3"]]}})
我再次运行lein deps
,然后大量的文件被下载。一切正常,项目仍然能够运行。现在我要在handler.clj
中添加一行代码:
(ns hello-world.handler
(:use compojure.core)
(:use ring.middleware.json-params) ;;; <---===/// Here's the line I added
(:require [compojure.handler :as handler]
[compojure.route :as route]))
(defroutes app-routes
(GET "/" [] "Hello World")
(route/not-found "Not Found"))
(def app
(handler/site app-routes))
现在我明白了
java.io.FileNotFoundException: Could not locate ring/middleware/json_params__init.class or ring/middleware/json_params.clj on classpath:
at clojure.lang.RT.load (RT.java:432)
clojure.lang.RT.load (RT.java:400)
clojure.core$load$fn__4890.invoke (core.clj:5415)
clojure.core$load.doInvoke (core.clj:5414)
因为我是完全不懂工具链的新手,所以我不知道如何设置或检查类路径,也不知道json_params
由leiningen放置在哪里,甚至不知道如何查看类文件以找到应该使用的名称。
除了针对这个问题的具体解决方案外,我也希望得到一些新手入门的指导,以便将来可以自己解决类似的简单问题。
lein ring server
正在工作。 - Reb.Cabinnrepl-jack-in
解决了问题。看起来更改project.clj后,您必须从project.clj目录重新启动nrepl
。有道理。谢谢你的提示! - Reb.Cabin