非常感谢你尝试帮助@alexmiller。你有没有推荐的地方可以去学习ClassLoader和相关JVM的背景知识?我很尴尬的是,我无法自己解决这个问题。
我已经修改了`add-test-lib.clj`,使其与`add-lib`的最新版本(现在已更名为`add-libs`)相兼容,并按照您提供的示例设置了`DynamicClassLoader`。
(->>(Thread/currentThread)
(.getContextClassLoader)
(clojure.lang.DynamicClassLoader.)
(.setContextClassLoader (Thread/currentThread)))
(use 'clojure.tools.deps.alpha.repl)
(add-libs {'thi.ng/geom {:mvn/version "1.0.0-RC4"}})
(require `thi.ng.geom.svg.core)
(thi.ng.geom.svg.core/circle [0 1] 6)
现在我已经用最新版本运行了
clj -Sdeps '{:deps {org.clojure/tools.deps.alpha {:git/url "
https://github.com/clojure/tools.deps.alpha.git :sha "241cd24c35ba770aea4773ea161d45276e5d3a73"}}}' add-lib-test.clj
同样,它在大纲中运行良好,但通过文件运行时却不行。不过情况已经有所改善 :) 我猜测类加载器仍然存在问题,或者文件的非REPL类路径(这是我稍微有些模糊的其他术语)存在错误。
{:clojure.main/message
"Syntax error (FileNotFoundException) compiling at (add-lib-test.clj:4:1).\nCould not locate thi/ng/geom/svg/core__init.class, thi/ng/geom/svg/core.clj or thi/ng/geom/svg/core.cljc on classpath.\n",
:clojure.main/triage
{:clojure.error/phase :compile-syntax-check,
:clojure.error/line 4,
:clojure.error/column 1,
:clojure.error/source "add-lib-test.clj",
:clojure.error/path "add-lib-test.clj",
:clojure.error/class java.io.FileNotFoundException,
:clojure.error/cause
"Could not locate thi/ng/geom/svg/core__init.class, thi/ng/geom/svg/core.clj or thi/ng/geom/svg/core.cljc on classpath."},
:clojure.main/trace
{:via
[{:type clojure.lang.Compiler$CompilerException,
:message
"Syntax error compiling at (/home/geokon/add-lib-test.clj:4:1).",
:data
{:clojure.error/phase :compile-syntax-check,
:clojure.error/line 4,
:clojure.error/column 1,
:clojure.error/source "/home/geokon/add-lib-test.clj"},
:at [clojure.lang.Compiler load "Compiler.java" 7648]}
{:type java.io.FileNotFoundException,
:message
"Could not locate thi/ng/geom/svg/core__init.class, thi/ng/geom/svg/core.clj or thi/ng/geom/svg/core.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]
[用户$评估4834 invokeStatic "add-lib-test.clj" 4]
[用户$评估4834 invoke "add-lib-test.clj" 4]
[clojure.lang.Compiler eval "Compiler.java" 7177]
[clojure.lang.Compiler load "Compiler.java" 7636]
[clojure.lang.Compiler loadFile "Compiler.java" 7574]
[clojure.main$load_script invokeStatic "main.clj" 475]
[clojure.main$script_opt invokeStatic "main.clj" 535]
[clojure.main$script_opt invoke "main.clj" 530]
[clojure.main$main invokeStatic "main.clj" 664]
[clojure.main$main doInvoke "main.clj" 616]
[clojure.lang.RestFn applyTo "RestFn.java" 137]
[clojure.lang Var applyTo "Var.java" 705]
[clojure.main main "main.java" 40]],
:cause
"无法在类路径中找到 thi/ng/geom/svg/core__init.class, thi/ng/geom/svg/core.clj 或 thi/ng/geom/svg/core.cljc。",
:phase :compile-syntax-check}}