如何运行.clj文件作为脚本使用leningen? [英] How to run .clj file as a script using leningen?

查看:461
本文介绍了如何运行.clj文件作为脚本使用leningen?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是之后的第二个问题Leiningen中的独立Clojure包?



例如,我有一个文件 hello_world.clj 我可以使用



java -cp clojure.jar clojure.main hello_world.clj

由于 lein 已经包含 Clojure (因为我可以运行 lein repl 是否有办法做同样的事情



lein script hello_world.clj by lein? / p>

解决方案

使用 lein-exec < a> plugin,example from readme.md

  cat foo.clj | lein2 exec 
lein2 exec -e'(printlnfoo(+ 20 30))'
lein2 exec -ep(使用'foo.bar'
lein2 exec -p script / run-server.clj -p 8088
lein2 exec〜/ common / delete-logs.clj


This is the second question after Is there a standalone Clojure package within Leiningen?

For example, I have a file hello_world.clj, and I can run it using

java -cp clojure.jar clojure.main hello_world.clj.

Since lein already contains Clojure (because I can run lein repl directly), is there a way to do the same thing like

lein script hello_world.clj by lein?

解决方案

use lein-exec plugin, example from readme.md

cat foo.clj | lein2 exec
lein2 exec -e '(println "foo" (+ 20 30))'
lein2 exec -ep "(use 'foo.bar) (pprint (map baz (range 200)))"
lein2 exec -p script/run-server.clj -p 8088
lein2 exec ~/common/delete-logs.clj

这篇关于如何运行.clj文件作为脚本使用leningen?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆