Saturday 3 October 2015

'could not find class clojure.main' when running lein repl

Sometimes I think I should be banned from writing code. Whilst working on a deliberately minimal http-kit app I kept hitting this brick wall …

» ~/git/clojure-learning/http-kit/simple/ lein repl
Error: Could not find or load main class clojure.main
Exception in thread "Thread-3" clojure.lang.ExceptionInfo: Subprocess failed {:exit-code 1}

It was driving me nuts as I had about ten lines of code over two files and couldn’t spot it. Here’s the files

;; simple/project.clj
(defproject simple "0.0.0-SNAPSHOT"
  :dependancies [[org.clojure/clojure "1.7.0"]
                 [http-kit "2.1.19"]])
;; simple/src/simple/core.clj
(ns simple.core
  (:use org.httpkit.server))

(defn app [req]
  {:status  200
   :headers {"Content-Type" "text/html"}
   :body    "hello HTTP!"})

(run-server app {:port 8080})

Can you spot the error? A typo in simple/project.clj, instead of :dependencies I had :dependancies.

That fixed it. I and I hope if you’re on this page via a search engine, that I’ve saved you some earth time.