ris*_*ant 2 java jar clojure leiningen
我正在和leiningen一起学习clojure。我编写了一个简单的代码来测试lein & java -jar命令。这是我的project.clj文件:
$ cat project.clj
(defproject hello "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"]]
:main ^:skip-aot hello.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
Run Code Online (Sandbox Code Playgroud)
这是我的源代码:
$ cat src/hello/core.clj
(ns hello.core
(:gen-class))
(defn -main
[& args]
(print "Hello, World!"))
Run Code Online (Sandbox Code Playgroud)
当我使用lein运行此代码时,它工作正常。它显示在这里
$ lein run
Hello, World!$
Run Code Online (Sandbox Code Playgroud)
当我尝试运行java -jar 时,它没有用
$ lein uberjar
Compiling hello.core
Created /home/rishi/hello/target/uberjar/hello-0.1.0-SNAPSHOT.jar
Created /home/rishi/hello/target/uberjar/hello-0.1.0-SNAPSHOT-standalone.jar
$ java -jar target/uberjar/hello-0.1.0-SNAPSHOT-standalone.jar
Run Code Online (Sandbox Code Playgroud)
我不明白,为什么我没有使用java -jar获得所需的输出?
如果我在源文件中用println替换print,我会同时获得lein run和java -jar所需的输出。
您的流程输出已缓冲。print不刷新输出。大多数情况下,您的输出流将设置为自动刷新换行符,这就是println显示的原因。如果您需要在没有换行符的情况下刷新,您可以调用该(flush)函数。
| 归档时间: |
|
| 查看次数: |
363 次 |
| 最近记录: |