0
votes

I am using the beginner guide in the pedestal guide but when trying to use use a namespace (require 'test) I get the following error messge: “Execution error (FileNotFoundException) at user/eval2012 (REPL:1). Could not locate test__init.class, test.clj or test.cljc on classpath.”

The same thing happens when trying (require 'hello)

I am using lein repl.

I have a directory called test and under src theres is a file called test.clj

test/src/test.clj:

(ns test
(:require [io.pedestal.http :as http]
[io.pedesteal.http.route :as route]))

test/src/hello.clj:

(defn respond-hello [request]
{:status 200 :body “Herllo world”})

any ideas?

test/deps.edn:

:deps                                                
 {io.pedestal/pedestal.service {:mvn/version "0.5.7"}
  io.pedestal/pedestal.route   {:mvn/version "0.5.7"}
  io.pedestal/pedestal.jetty   {:mvn/version "0.5.7"}
  org.slf4j/slf4j-simple       {:mvn/version "1.7.28"}}
 :paths ["src"]}
1
To be sure, you would have to show us your file/directory structures and your project.clj, but at first glance: If these are supposed to be tests, there usually is no src under the test dir - same for hello, but this lacks the ns? - cfrick
there is no project.clj, I am just following the pedestal tutorial. the file structucture is shown above, i.e: test/src/test.clj and test/src/hello.clj. the name test is jut arbitary, it has nothing to do with any test. I added deps.edn above - Jonas Fredriksson
Then you should not use lein repl? It will not find the files, if you configure things for the clojure cli tools. so the first level of test in your directory structure is the name of your project then and you are actually using all those tools inside it? For future reference: don't do that in questions - it confuses people (like me) - just assume the project root. - cfrick

1 Answers

2
votes

The clj repl differs from lein repl. To use lein repl, you need a project.clj file.

I went through Pedestal's beginner guide successfully using the suggested clj, but I got your error when using lein repl:

user=> (require 'test)
Execution error (FileNotFoundException) at user/eval2006 (REPL:1).

user=> (require 'hello)
Execution error (FileNotFoundException) at user/eval2008 (REPL:1).
Could not locate hello__init.class, hello.clj or hello.cljc on classpath.

I looked at the difference between a clj project and a Leiningen project, and here's what I see:

  • clj uses deps.edn. Leiningen puts the dependencies in project.clj
  • clj has :paths ["src"]. Leiningen has :main and :target-path in project.clj

So to switch from clj to lein repl, I added the project.clj file with this:

(defproject pedestal "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.10.1"]
                 [io.pedestal/pedestal.service "0.5.7"]
                 [io.pedestal/pedestal.route "0.5.7"]
                 [io.pedestal/pedestal.jetty "0.5.7"]]
  :main ^:skip-aot test
  :target-path "target/%s")

which follows my directory structure...

.../pedestal/src/test.clj
.../pedestal/project.clj
.../...

When I started it again, I didn't even need (require 'test) nor even(test/start). (start) did the trick, and the page would load

Working webpage

Leiningen differs from barebones clj tool. It points to starting files(?) differently and pulls in dependencies differently than a barebones clj project, which the guide recommended.

From your question, I don't see mention of a project.clj, so maybe this is what you need.