Xia*_*ian 10 installation clojure compojure
我正在尝试各种入门示例,我可以获得一个基本的hello world示例,在路由中使用基本HTML
(ns hello-world
(:use compojure.core ring.adapter.jetty)
(:require [compojure.route :as route]))
(defroutes example
(GET "/" [] "<h1>Hello World Wide Web!</h1>"))
(run-jetty example {:port 8080})
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用像这样的html助手时
(ns hello-world
(:use compojure ring.adapter.jetty)
(:require [compojure.route :as route]))
(defroutes example
(GET "/" []
(html [:h1 "Hello World"])))
(run-jetty example {:port 8080})
Run Code Online (Sandbox Code Playgroud)
然后我收到以下错误
[null]线程"main"中的异常java.io.FileNotFoundException:无法在类路径上找到compojure__init.class或compojure.clj:(core.clj:1)
正如W55tKQbuRu28Q4xv在评论中提到的那样,您可以(:use compojure ...)
在第二个示例中使用.你应该切换到(:use compojure.core ...)
然后为你使用的其他功能引入一些额外的依赖(比如hiccup
(< - 这是一个指向GitHub repo的链接),现在它是一个单独的项目,用于HTML构建DSL).
我的猜测是你在使用Compojure 0.4时尝试遵循为Compojure 0.3编写的一些教程.后者根本不包括compojure
命名空间,并且已经过多了,基本的HTTP处理被委托给ring
各个其他功能部分分离出来(如上所述hiccup
).
幸运的是,在0.3 - > 0.4过渡期间有很好的资源,例如Brenton Ashworth的博客文章.如果你找不到那些已经从Compojure中删除的东西,你很可能会从那里学到如何找到它.另请参阅有关Compojure Google小组的后续讨论,以获取勘误表和其他详细信息.