Over a million developers have joined DZone.

Clojure/Emacs/nrepl: Ctrl X + Ctrl E leads to FileNotFoundException

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

I’ve been playing around with Clojure using Emacs and nrepl recently and my normal work flow is to write some code in Emacs and then have it evaluated in nrepl by typing Ctrl X + Ctrl E at the end of the function.

I tried this once recently and got the following exception instead of a successful evaluation:

FileNotFoundException Could not locate ranking_algorithms/ranking__init.class or ranking_algorithms/ranking.clj on classpath: clojure.lang.RT.load (RT.java:432)

I was a bit surprised because I had nrepl running already (via (Meta + X) + Enter + nrepl-jack-in) and I’d only ever seen that exception refer to dependencies which weren’t in my project.clj file at the time I launched nrepl.

I eventually came across this StackOverflow post which suggested that you either launch nrepl using leiningen and then connect to it from Emacs or have your project.clj open when running (Meta + X) + Enter + nrepl-jack-in.

To launch nrepl from leiningen we’d run the following command from the terminal:

$ lein repl
nREPL server started on port 52265
REPL-y 0.1.0-beta10
Clojure 1.4.0
    Exit: Control+D or (exit) or (quit)
Commands: (user/help)
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
          (user/sourcery function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
Examples from clojuredocs.org: [clojuredocs or cdoc]
          (user/clojuredocs name-here)
          (user/clojuredocs "ns-here" "name-here")

We can then connect to that nrepl server from Emacs by typing (Meta + X) + Enter + nrepl which seems to work quite nicely.

To check the nrepl-jack-in approach works when we’ve got project.clj open we need to first kill the existing server by typing (Meta + X) + Enter + nrepl-quit.

Now if we type (Meta + X) + Enter + nrepl-jack-in our functions are evaluated correctly and all is well with the world again.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Published at DZone with permission of Mark Needham, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}