i am trying to get the
Using local libraries
in the to work from the Deps and CLI Guide.
i’ve set things up exactly as written inside a directory called depscliguide2:
% tree
.
├── hello-world
│ ├── deps.edn
│ └── src
│ └── hello.clj
├── nolib
│ ├── deps.edn
│ └── src
│ └── sayhello.clj
└── time-lib
├── deps.edn
└── src
└── hello_time.clj
the nolib dir is just there to make sure that its deps.edn:
{:deps
{clojure.java-time/clojure.java-time {:mvn/version "1.2.0"}}}
can actually grab the java-time 1.2.0 lib.
sayhello.clj is really hello.clj:
ns sayhello
(:require [java-time.api :as t]))
(defn time-str
"Returns a string representation of a datetime in the local time zone."
[instant]
(t/format
(t/with-zone (t/formatter "hh:mm a") (t/zone-id))
instant))
(defn run [opts]
(println "Hello world, the time is" (time-str (t/instant))))
% clj -X sayhello/run
works just fine
the code in
time-lib
hello-world
has been copied from the web page (filenames use ‘_’ for ns with ‘-’ etc)
however, when i go into hello-world and
% clj -X hello/run
i get
Execution error (FileNotFoundException) at hello-time/eval234$loading (hello_time.clj:1).
Could not locate java_time/api__init.class, java_time/api.clj or java_time/api.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
Full report at:
/tmp/clojure-16741433504450784431.edn
/tmp/clojure-16741433504450784431.edn
doesn’t shed any further light beyond just repeating that it can’t locate the java-time lib.
if i copy hello.clj into time-lib/src and run it from there, everything works nicely.
so my conclusion is that the hello-time/deps.edn
{:deps
{time-lib/time-lib {:local/root "../time-lib"}}}
is unable (for some mysterious reason) to find the java-time lib using the hello_time.clj:
ns hello-time
(:require [java-time.api :as t]))
which is what the hello-world/deps.edn asks it to do:
{:deps
{time-lib/time-lib {:local/root "../time-lib"}}}
i’m assuming there is something wrong with :local/root, but don’t know what (adjusting the …/ didn’t succeed) based on:
- the error message (FileNotFoundException).
- the fact that time-lib/src/hello.clj does work.
i also saw
Modify hello-world/deps.edn to use a local coordinate that refers to the root directory of the time-lib library (make sure to update the path for your machine)
but don’t know what they mean by “update the path” since i thought the deps.edn file is supposed to do just that.
why isn’t this working (especially since it is copied directly from the instructions on the webpage)?