Question

I am new to Clojure, leiningen, and java tool chains (but not to lisp, functional programming, software in general). I'm trying to bootstrap some RESTful web services in Compojure.

I had no trouble getting started with compojure, following the instructions at

https://github.com/weavejester/compojure/wiki/Getting-Started

I am now trying to incrementally add in functionality from the now-outdated web site

http://mmcgrana.github.com/2010/08/clojure-rest-api.html

Starting with the working leiningen project from the first link above (it works via lein ring start, I add ONE line to project.clj

(defproject hello-world "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [ring-json-params "0.1.3"]  ;;; <---===/// Here's the line I added
                 [compojure "1.1.5"]]
  :plugins [[lein-ring "0.8.2"]]
  :ring {:handler hello-world.handler/app}
  :profiles
  {:dev {:dependencies [[ring-mock "0.1.3"]]}})

Then I rerun lein deps and a bunch of stuff downloads. All good, the project still works. Now I add one line to handler.clj:

(ns hello-world.handler
  (:use     compojure.core)
  (:use     ring.middleware.json-params)  ;;; <---===/// Here's the line I added
  (:require [compojure.handler :as handler]
            [compojure.route :as route]))

(defroutes app-routes
  (GET "/" [] "Hello World")
  (route/not-found "Not Found"))

(def app
  (handler/site app-routes))

And now I get

java.io.FileNotFoundException: Could not locate ring/middleware/json_params__init.class or ring/middleware/json_params.clj on classpath: 
 at clojure.lang.RT.load (RT.java:432)
    clojure.lang.RT.load (RT.java:400)
    clojure.core$load$fn__4890.invoke (core.clj:5415)
    clojure.core$load.doInvoke (core.clj:5414)

Since I am a total noob to the toolchain, I don't know how to set or inspect the classpath or to find out where json_params was deposited by leiningen, or even how to look inside the class files to find out what the name should have been.

In addition to a specific solution to this problem, I would appreciate pointers to newbie stuff so maybe I can solve straightforward problems like this on my own in the future.

Was it helpful?

Solution

Did you get that error when you start the server? Nothing is wrong on my enviroment. enter image description here

Here's what i have done:

lein new compojure hello

Then change project.clj as you do and run:

lein deps

At last add:

(:use ring.middleware.json-params)

to handle.clj

Start server, no error occurs.

I suggest you building a new project and try again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top