Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
985 views
in Technique[技术] by (71.8m points)

dependencies - Import dependency "clojure.tools.trace" to REPL in Clojure failed: File not found

I'm new to Clojure, trying to debug my program with the function trace.

I tried this in REPL:

(require '[clojure.tools.trace :as trace])

But it throws an exception:

Execution error (FileNotFoundException) at user/eval199 (REPL:1).
Could not locate clojure/tools/trace__init.class, clojure/tools/trace.clj or clojure/tools/trace.cljc on classpath.

*e says this:

#error {
 :cause "Could not locate clojure/tools/trace__init.class, clojure/tools/trace.clj or clojure/tools/trace.cljc on classpath."
 :via
 [{:type java.io.FileNotFoundException
   :message "Could not locate clojure/tools/trace__init.class, clojure/tools/trace.clj or clojure/tools/trace.cljc on classpath."
   :at [clojure.lang.RT load "RT.java" 462]}]
 :trace
 [[clojure.lang.RT load "RT.java" 462]
  [clojure.lang.RT load "RT.java" 424]
  [clojure.core$load$fn__6839 invoke "core.clj" 6126]
  [clojure.core$load invokeStatic "core.clj" 6125]
  [clojure.core$load doInvoke "core.clj" 6109]
  [clojure.lang.RestFn invoke "RestFn.java" 408]
  [clojure.core$load_one invokeStatic "core.clj" 5908]
  [clojure.core$load_one invoke "core.clj" 5903]
  [clojure.core$load_lib$fn__6780 invoke "core.clj" 5948]
  [clojure.core$load_lib invokeStatic "core.clj" 5947]
  [clojure.core$load_lib doInvoke "core.clj" 5928]
  [clojure.lang.RestFn applyTo "RestFn.java" 142]
  [clojure.core$apply invokeStatic "core.clj" 667]
  [clojure.core$load_libs invokeStatic "core.clj" 5985]
  [clojure.core$load_libs doInvoke "core.clj" 5969]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.core$apply invokeStatic "core.clj" 667]
  [clojure.core$require invokeStatic "core.clj" 6007]
  [clojure.core$require doInvoke "core.clj" 6007]
  [clojure.lang.RestFn invoke "RestFn.java" 408]
  [user$eval193 invokeStatic "NO_SOURCE_FILE" 1]
  [user$eval193 invoke "NO_SOURCE_FILE" 1]
  [clojure.lang.Compiler eval "Compiler.java" 7177]
  [clojure.lang.Compiler eval "Compiler.java" 7132]
  [clojure.core$eval invokeStatic "core.clj" 3214]
  [clojure.core$eval invoke "core.clj" 3210]
  [clojure.main$repl$read_eval_print__9086$fn__9089 invoke "main.clj" 437]
  [clojure.main$repl$read_eval_print__9086 invoke "main.clj" 437]
  [clojure.main$repl$fn__9095 invoke "main.clj" 458]
  [clojure.main$repl invokeStatic "main.clj" 458]
  [clojure.main$repl_opt invokeStatic "main.clj" 522]
  [clojure.main$main invokeStatic "main.clj" 667]
  [clojure.main$main doInvoke "main.clj" 616]
  [clojure.lang.RestFn invoke "RestFn.java" 397]
  [clojure.lang.AFn applyToHelper "AFn.java" 152]
  [clojure.lang.RestFn applyTo "RestFn.java" 132]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.main main "main.java" 40]]}

I've searched for the docs of clojure.tools.trace on Github.

It says you need import dependency, but the dependency information are for Clojure CLI, Leiningen or Maven, not for REPL in clojure.

(When I'm saying REPL in clojure, I actually mean clj, sorry for the vague description)

So I stuck here. Can anyone tell me how to fix this and what' happenning?

question from:https://stackoverflow.com/questions/65895898/import-dependency-clojure-tools-trace-to-repl-in-clojure-failed-file-not-foun

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since you're using clj (the Clojure CLI), you'll need to add the clojure.tools.trace library to your deps.edn file:

seanc@DESKTOP-30ICA76:~/clojure$ mkdir lyhokia
seanc@DESKTOP-30ICA76:~/clojure$ cd lyhokia/
seanc@DESKTOP-30ICA76:~/clojure/lyhokia$ vi deps.edn
<add the library>
seanc@DESKTOP-30ICA76:~/clojure/lyhokia$ cat deps.edn
{:deps {org.clojure/tools.trace {:mvn/version "0.7.10"}}}
seanc@DESKTOP-30ICA76:~/clojure/lyhokia$ clj
Clojure 1.10.1
user=> (require '[clojure.tools.trace :as trace])
nil
user=> (trace/trace (* 1 2 3))
TRACE: 6
6
user=>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...