如何在 Leiningen 中提前编译单个文件? (Clojure)

How to do ahead-of-time compilation of a single file in Leiningen? (Clojure)

根据 clj-facebook-graph 的自述文件:

Installation

This project is built with Leiningen and prepared for use with Swank Clojure. Pay attention that on first-time use you have to invoke "lein compile" to compile the clj_facebook_graph.FacebookGraphException ahead-of-time, otherwise you will get a ClassNotFoundException for this class.

我的问题是,"ahead-of-time"编译是怎么做到的。 顺便说一下,我在上述库上尝试了 运行 lein compile 但出现以下错误:

[WARNING] POM for 'org.apache.httpcomponents:httpcore:pom:4.1.2:compile' is invalid.

Its dependencies (if any) will NOT be available to the current build.
[WARNING] POM for 'commons-logging:commons-logging:pom:1.1.1:compile' is invalid.

Its dependencies (if any) will NOT be available to the current build.
Copying 14 files to /root/clojure/clj-facebook-graph/lib
Copying 20 files to /root/clojure/clj-facebook-graph/lib/dev
Exception in thread "main" java.lang.RuntimeException: java.util.zip.ZipException: error in opening zip file (NO_SOURCE_FILE:0)
        at clojure.lang.Compiler.eval(Compiler.java:5441)
        at clojure.lang.Compiler.eval(Compiler.java:5392)
        at clojure.core$eval.invoke(core.clj:2382)
        at clojure.main$eval_opt.invoke(main.clj:235)
        at clojure.main$initialize.invoke(main.clj:254)
        at clojure.main$script_opt.invoke(main.clj:270)
        at clojure.main$main.doInvoke(main.clj:354)
        at clojure.lang.RestFn.invoke(RestFn.java:457)
        at clojure.lang.Var.invoke(Var.java:377)
        at clojure.lang.AFn.applyToHelper(AFn.java:172)
        at clojure.lang.Var.applyTo(Var.java:482)
        at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: java.util.zip.ZipException: error in opening zip file
        at clojure.lang.LazySeq.sval(LazySeq.java:47)
        at clojure.lang.LazySeq.seq(LazySeq.java:56)
        at clojure.lang.Cons.next(Cons.java:39)
        at clojure.lang.RT.next(RT.java:560)
        at clojure.core$next.invoke(core.clj:61)
        at leiningen.deps$extract_native_deps.invoke(deps.clj:174)
        at leiningen.deps$deps.doInvoke(deps.clj:200)
        at clojure.lang.RestFn.invoke(RestFn.java:410)
        at leiningen.compile$prep.invoke(compile.clj:150)
        at leiningen.compile$eval_in_project.doInvoke(compile.clj:207)
        at clojure.lang.RestFn.invoke(RestFn.java:425)
        at leiningen.compile$compile.invoke(compile.clj:283)
        at clojure.lang.Var.invoke(Var.java:365)
        at clojure.lang.AFn.applyToHelper(AFn.java:161)
        at clojure.lang.Var.applyTo(Var.java:482)
        at clojure.core$apply.invoke(core.clj:542)
        at leiningen.core$apply_task.invoke(core.clj:262)
        at leiningen.core$_main.doInvoke(core.clj:329)
        at clojure.lang.RestFn.invoke(RestFn.java:410)
        at clojure.lang.AFn.applyToHelper(AFn.java:161)
        at clojure.lang.RestFn.applyTo(RestFn.java:132)
        at clojure.core$apply.invoke(core.clj:542)
        at leiningen.core$_main.invoke(core.clj:332)
        at user$eval73.invoke(NO_SOURCE_FILE:1)
        at clojure.lang.Compiler.eval(Compiler.java:5425)
        ... 11 more
Caused by: java.util.zip.ZipException: error in opening zip file
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:215)
        at java.util.zip.ZipFile.<init>(ZipFile.java:145)
        at java.util.jar.JarFile.<init>(JarFile.java:154)
        at java.util.jar.JarFile.<init>(JarFile.java:118)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at clojure.lang.Reflector.invokeConstructor(Reflector.java:160)
        at leiningen.deps$extract_native_deps$fn__2488.invoke(deps.clj:174)
        at clojure.core$map$fn__3699.invoke(core.clj:2096)
        at clojure.lang.LazySeq.sval(LazySeq.java:42)
        ... 35 more

要使用 leiningen 实现 aot 编译,您只需在 project.clj 的顶层或相关配置文件中添加 :aot :all,如果您愿意的话。

您甚至可以只编译您选择的命名空间。 请参阅此 project.clj 示例:https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L242

我已经无数次编译 aot 和 uberjar'ed 一个依赖这个库的 lein 项目。

我知道 clj-facebook-graph 已经很老了并且没有得到积极维护(例如:他们正在谈论 swank-clojureswank-clojure 很久以前就被 NRepl 取代了。)

希望对您有所帮助