无法在类路径中找到 compojure

发布于 2024-09-02 18:49:09 字数 694 浏览 9 评论 0原文

我正在尝试各种入门示例,我可以得到一个在路由中使用基本 HTML 的基本 hello world 示例,

(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})

但是当我尝试像这样使用 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})

,我收到以下错误

[null] 线程中的异常“ main" java.io.FileNotFoundException: 无法在类路径上找到 compojure__init.class 或 compojure.clj: (core.clj:1)

I am trying the various Getting started examples and I can get a basic hello world example working with basic HTML in the route as such

(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})

But when I attempt to use the html helpers like so

(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})

Then I get the following error

[null] Exception in thread "main" java.io.FileNotFoundException: Could not locate compojure__init.class or compojure.clj on classpath: (core.clj:1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

榕城若虚 2024-09-09 18:49:09

正如 W55tKQbuRu28Q4xv 在评论中提到的,您在第二个示例中使用 (:use compojure ...) 。您应该切换到 (:use compojure.core ...) ,然后可能会为您使用的其他功能引入一些额外的依赖项(例如 hiccup (<- 这是 GitHub 存储库的链接),现在是一个单独的项目,用于 HTML 构建 DSL )。

我的猜测是,您在使用 Compojure 0.4 时尝试遵循为 Compojure 0.3 编写的一些教程。后者根本不包含 compojure 命名空间,并且已经精简了很多,基本的 HTTP 处理委托给 ring 和各种其他功能分拆到单独的项目(如前面提到的 hiccup)。

幸运的是0.3上有很好的资源-> 0.4 过渡,例如 此博客条目 布伦顿·阿什沃思。如果您无法找到已从 Compojure 中删除的内容,那么您现在很可能能够从中了解在哪里可以找到它。另请参阅 Compojure Google 上的此后续讨论组以获取勘误表和其他详细信息。

As W55tKQbuRu28Q4xv mentions in a comment, you use (:use compojure ...) in the second example. You should switch to (:use compojure.core ...) and then maybe pull in some additional dependencies for the other functionality that you use (like hiccup (<- this is a link to the GitHub repo), which is now a separate project, for the HTML-building DSL).

My guess is that you're trying to follow some tutorials written for Compojure 0.3 while using Compojure 0.4. The latter does not include the compojure namespace at all and has been slimmed down a lot, with the basic HTTP handling delegated to ring and various other pieces of functionality spun off to separate projects (like the aforementioned hiccup).

Fortunately there are good resources on the 0.3 -> 0.4 transition, e.g. this blog entry by Brenton Ashworth. If you can't find something that's been removed from Compojure proper, chances are you'll be able to learn where to find it now from that. See also this follow-up discussion on Compojure's Google group for errata and additional details.

╰つ倒转 2024-09-09 18:49:09

我玩了一个 Compojure“Hello World”并遇到了这个问题(以及许多其他在我大脑中变得混乱的问题)。另一个复杂之处是网络上的许多 Compojure 文档已经过时。最重要的是,这些是您要遵循的步骤:

  1. 拥有最新版本的 Leiningen< /a>.确保遵循 github 站点上的安装说明。 (不要通过 macports;他们的 Leiningen 已经过时了。)

  2. 遵循 Compojure 说明此处

请注意文件名不正确。它应该是 src/hello_www/core.clj 而不是 src/hello-www/core.clj。

I played around with a Compojure "Hello World" and had this problem (as well as many others that are getting muddled in my brain). Another complication is a lot of the Compojure documentation on the web is already out of date. Bottom line, these are the step you want to follow:

  1. Have an up-to-date version of Leiningen. Make sure you follow the installation instructions on the github site. (Do not go through macports; their Leiningen is out of date.)

  2. Follow Compojure instructions here.

Note that the file name is incorrect. It should be src/hello_www/core.clj NOT src/hello-www/core.clj.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文