depstar
使用外壳程序运行 AOT 编译过程,并且确实使用了 clojure.main
,但没有简单的方法将 --report
传递给该子进程。然而,您可以传递 :jvm-opts
到 depstar
,它将相应地将它们传递到子进程。
:jvm-opts '["-Dclojure.main.report=stderr"]'
depstar
会将输出写入标准输出/标准错误。
(! 650)-> clojure -X:jar :jar test.jar :main-class foo.bar :aot true
[main] WARN hf.depstar.uberjar - :aot is not recommended for a 'thin' JAR!
[main] INFO hf.depstar.uberjar - Compiling foo.bar ...
Execution error (FileNotFoundException) at user/eval136 (REPL:1).
Could not locate foo/bar__init.class, foo/bar.clj or foo/bar.cljc on classpath.
Full report at:
/var/folders/p1/30gnjddx6p193frh670pl8nh0000gn/T/clojure-13601013524882075105.edn
[main] ERROR hf.depstar.uberjar - Compilation of foo.bar failed!
[main] ERROR hf.depstar.uberjar - AOT FAILED
以下是提供了 JVM 选项后的相同内容
(! 652)-> clojure -X:jar :jar test.jar :main-class foo.bar :aot true :jvm-opts '["-Dclojure.main.report=stderr"]'
[main] WARN hf.depstar.uberjar - :aot is not recommended for a 'thin' JAR!
[main] INFO hf.depstar.uberjar - Compiling foo.bar ...
{:clojure.main/message
"Execution error (FileNotFoundException) at user/eval136 (REPL:1).\nCould not locate foo/bar__init.class, foo/bar.clj or foo/bar.cljc on classpath.\n",
:clojure.main/triage
{:clojure.error/class java.io.FileNotFoundException,
:clojure.error/line 1,
:clojure.error/cause
"Could not locate foo/bar__init.class, foo/bar.clj or foo/bar.cljc on classpath.",
:clojure.error/symbol user/eval136,
:clojure.error/phase :execution},
:clojure.main/trace
{:via
[{:type java.io.FileNotFoundException,
:message
"Could not locate foo/bar__init.class, foo/bar.clj or foo/bar.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__6856 invoke "core.clj" 6115]
[clojure.core$load invokeStatic "core.clj" 6114]
[clojure.core$load doInvoke "core.clj" 6098]
[clojure.lang.RestFn invoke "RestFn.java" 408]
[clojure.core$load_one invokeStatic "core.clj" 5897]
[clojure.core$compile$fn__6861 invoke "core.clj" 6125]
[clojure.core$compile invokeStatic "core.clj" 6125]
[clojure.core$compile invoke "core.clj" 6117]
[user$eval136 invokeStatic "NO_SOURCE_FILE" 1]
[user$eval136 invoke "NO_SOURCE_FILE" 1]
[clojure.lang.Compiler eval "Compiler.java" 7181]
[clojure.lang.Compiler eval "Compiler.java" 7136]
[clojure.core$eval invokeStatic "core.clj" 3202]
[clojure.main$eval_opt invokeStatic "main.clj" 488]
[clojure.main$eval_opt invoke "main.clj" 482]
[clojure.main$initialize invokeStatic "main.clj" 508]
[clojure.main$null_opt invokeStatic "main.clj" 542]
[clojure.main$null_opt invoke "main.clj" 539]
[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
"Could not locate foo/bar__init.class, foo/bar.clj or foo/bar.cljc on classpath."}}
Execution error (FileNotFoundException) at user/eval136 (REPL:1).
Could not locate foo/bar__init.class, foo/bar.clj or foo/bar.cljc on classpath.
[main] ERROR hf.depstar.uberjar - Compilation of foo.bar failed!
[main] ERROR hf.depstar.uberjar - AOT FAILED
继 Alex 的回答中的评论之后
使用 -X 确实 执行了 clojure.main
,但它仅用于 CLI API 模型,然后调用一个或多个 "exec 函数"。您不能向它传递 --report
,但是您可以使用 JVM 选项。
(! 667)-> cat src/thrower.clj
(ns thrower)
(defn bang [_] (throw (ex-info "foo" {})))
(! 668)-> clojure -X thrower/bang
Execution error (ExceptionInfo) at thrower/bang (thrower.clj:3).
foo
Full report at:
/var/folders/p1/30gnjddx6p193frh670pl8nh0000gn/T/clojure-248093423269602852.edn
(! 669)-> clojure -J-Dclojure.main.report=stderr -X thrower/bang
{:clojure.main/message
"Execution error (ExceptionInfo) at thrower/bang (thrower.clj:3).\nfoo\n",
:clojure.main/triage
{:clojure.error/class clojure.lang.ExceptionInfo,
:clojure.error/line 3,
:clojure.error/cause "foo",
:clojure.error/symbol thrower/bang,
:clojure.error/source "thrower.clj",
:clojure.error/phase :execution},
:clojure.main/trace
{:via
[{:type clojure.lang.ExceptionInfo,
:message "foo",
:data {},
:at [thrower$bang invokeStatic "thrower.clj" 3]}],
:trace
[[thrower$bang invokeStatic "thrower.clj" 3]
[thrower$bang invoke "thrower.clj" 3]
[clojure.lang.AFn applyToHelper "AFn.java" 154]
[clojure.lang.AFn applyTo "AFn.java" 144]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.core$apply invokeStatic "core.clj" 667]
[clojure.core$apply invoke "core.clj" 662]
[clojure.run.exec$exec invokeStatic "exec.clj" 40]
[clojure.run.exec$exec doInvoke "exec.clj" 35]
[clojure.lang.RestFn invoke "RestFn.java" 423]
[clojure.run.exec$_main invokeStatic "exec.clj" 169]
[clojure.run.exec$_main doInvoke "exec.clj" 157]
[clojure.lang.RestFn applyTo "RestFn.java" 137]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.core$apply invokeStatic "core.clj" 667]
[clojure.main$main_opt invokeStatic "main.clj" 514]
[clojure.main$main_opt invoke "main.clj" 510]
[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 "foo",
:data {}}}
Execution error (ExceptionInfo) at thrower/bang (thrower.clj:3).
foo