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 h开发者_StackOverflow社区ello-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)
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.
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:
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.)
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.
精彩评论