【发布时间】:2017-12-11 14:29:14
【问题描述】:
我是第一次测试 Clojure,想写一个简单的 websocket 客户端应用程序。我找到了库https://github.com/stylefruits/gniazdo 并让代码工作(使用lein run)。但是,将代码编译到 jar 中(lein jar 或 lein uberjar 要么被卡住,要么需要很长时间(大约 1 小时后中止))
步骤:
lein new app testing- 修改了 src/testing/core.clj 和 project.clj(见下文)
-
lein jar(或lein uberjar)
为简单起见,我有这个非常简单的代码,它已经需要很长时间才能编译成一个 jar:
(ns testing.core
(:gen-class))
(require '[gniazdo.core :as ws])
(def socket
(ws/connect
"wss://some.url.com/"))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(ws/close socket))
project.clj:
(defproject testing "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[stylefruits/gniazdo "1.0.1"]]
:main ^:skip-aot testing.core
:aot [testing.core]
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
运行lein jar的输出:
$lein jar
Compiling testing.core
2017-12-11 14:15:14.813:INFO::main: Logging initialized @1352ms
什么都没有。这是正常行为(编译只需要很长时间)还是我在这里遗漏了什么? Clojure 看起来很有趣,但如果编译这么小的程序需要几个小时,那么在我的情况下部署可能是个问题。
【问题讨论】:
-
要么:1. 不要在顶层连接,要么:2. 不要 AOT 你的
testing.core命名空间。您认为应该如何将连接存储在 JAR 中?
标签: clojure compilation leiningen