How to embed a REPL in my Clojure application?

1.2k Views Asked by At

I'm trying to embed cider.nrepl in my clojure application so that I can connect to my running instance, inspect, fix, etc.

I'm including cider-nrepl in my leiningen profiles file:

:plugins [[cider/cider-nrepl "0.7.0"]]

And then in my core.clj:

(:require (cheshire [core :as c])
            [byte-streams :as bs]
            [clojail [core :as jail] [testers :as testers]]
            [clojure.tools.nrepl [server :as nrepl-server]]
            [cider.nrepl :refer (cider-nrepl-handler)])

(defn -main [& args]
  (println "Starting up REPL")
  (nrepl-server/start-server :bind "0.0.0.0" :port 7888 :handler cider-nrepl-handler))

The program compiles and runs ok. But when I try to connect to the REPL session in port 7888 I get the following stack trace:

ERROR: Unhandled REPL handler exception processing message {:id 0da185f2-38e8-4a83-9941-327b9806176b, :op clone} java.lang.NoClassDefFoundError: clojure/tools/nrepl/StdOutBuffer at clojure.tools.nrepl.middleware.session$session_out.invoke(session.clj:26) at clojure.tools.nrepl.middleware.session$create_session.invoke(session.clj:118) at clojure.tools.nrepl.middleware.session$create_session.invoke(session.clj:114)

Not sure how to proceed at this point. Googling StdOutBuffer didn't help either.

Update This is my full project.clj

(defproject ruler "1.0"
  :description "Autopal Rule Server"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [clojail "1.0.6"]
                 [com.rmoquin.bundle/jeromq "0.2.0"]
                 [cheshire "5.2.0"]
                 [byte-streams "0.1.10"]
                 [clj-time "0.7.0"]]
  :aot [ruler.core]
  :main ruler.core)

As stated above, cider-nrepl is included via leiningen's profiles file.

1

There are 1 best solutions below

1
On BEST ANSWER

I think the problem is that the dependency to the cider/cider-repl is a plugin dependency in your profile. If your project depends on that lib, it should be in your project.clj dependencies.

The lein profiles are for libs that you want to use during development but not in production, so they are not included as part of the war/jar/uberjar artefact.