0

I am working on the Compojure example from Clojure in Action page 232

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

But when I attempt to run it:

$ 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)
...

it appears that the statement

(:use compojure)

I have also heard that there was a major change between recent versions of compojure. What ma I doing wrong in setting up this compojure app? Is there a good tutorial online to help me get up and running?

1 Answer 1

3

You might want to try changing your use statement to:

(:use compojure.core)

That should do it.

I created a boilerplate template a while back for compojure that has a working example you can see here.

Even better, if you're using Leiningen - which you should - you can simply create a new compojure project like this:

$ lein new compojure hello-world

Checkout compojure's Getting Started for more.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer, and thanks for the boilerplate. Quick n00b question, how do I setup my project.clj and how do I run this on localhost?
I'd recommend using the lein template. Once you create the project, your project.clj should be good to go. Then just run this in your project root: lein ring server and it should open up the browser at the root of your webapp. Once this works, all you need is to implement your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.