【问题标题】:Compojure Example from Clojure in Action Not Working来自 Clojure 的 Compojure 示例在行动中不起作用
【发布时间】:2013-04-05 04:52:28
【问题描述】:

我正在研究 Clojure in Action 页面 232 中的 Compojure 示例

(ns compojure-test.core
  (:gen-class)
  (:use compojure))

(defroutes hello
  (GET "/" (html [:h1 "Hello world"]))
  (ANY "*" [404 "Page not found"]))

(run-server {:port 8080} "/*" (servlet hello))

但是当我尝试运行它时:

$ lein run
Exception in thread "main" java.lang.ClassNotFoundException: compojure-test.core
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
...

看来声明

(:use compojure)

我还听说最近的 compojure 版本之间发生了重大变化。我在设置这个 compojure 应用程序时做错了什么?有没有很好的在线教程可以帮助我启动和运行?

【问题讨论】:

    标签: clojure leiningen compojure


    【解决方案1】:

    您可能想尝试将您的 use 语句更改为:

    (:use compojure.core)

    应该可以的。

    不久前我为 compojure 创建了一个样板模板,其中有一个工作示例,您可以看到 here

    更好的是,如果您正在使用 Leiningen(您应该这样做),您可以像这样简单地创建一个新的 compojure 项目:

    $ lein new compojure hello-world

    查看 compojure 的 Getting Started 了解更多信息。

    【讨论】:

    • 感谢您的回答,也感谢您提供的样板文件。快速的 n00b 问题,如何设置我的 project.clj 以及如何在 localhost 上运行它?
    • 我建议使用 lein 模板。创建项目后,您的 project.clj 应该可以使用了。然后在您的项目根目录中运行它:lein ring server,它应该会在您的 web 应用程序的根目录中打开浏览器。一旦这工作,你所需要的就是实现你的代码。
    猜你喜欢
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    • 2018-09-02
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2014-04-21
    相关资源
    最近更新 更多