构建和部署Clojure应用程序的最佳实践:好的教程? [英] Best practices in building and deploying Clojure applications: good tutorials?

查看:109
本文介绍了构建和部署Clojure应用程序的最佳实践:好的教程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Clojure的新手,我开始尝试构建应用程序。

I am new to Clojure, and am beginning to experiment with building an application.

到目前为止,我看到的关于编译Clojure程序的教程的一切都涉及到交互性。例如,加载REPL并输入(加载文件this-or-that)运行,这很好,但还不够。

So far, everything I've seen about tutorials on compiling Clojure programs involves interactivity. For example, "load up the REPL and type (load-file "this-or-that") to run. This is fine, but it's not enough.

我习惯了C或Delphi这样的语言的编辑 - 编译运行语言,我本能地驱使它进行编辑,然后点击Mx compile。

I am so used to the edit-compile-run idioms of languages like C or Delp that I am instinctively driven to make edits, then hit "M-x compile".

问题是,lein uberjar,我理解是相当于make,即使对于一个hello世界也是痛苦地执行,所以我要弄清楚这个交互式开发的东西是如何工作的,停止

The problem is that "lein uberjar", which I understand is the equivalent to "make", is painfully slow to execute even for a hello world. So I'm going to have to figure out how this "interactive development" stuff works, stop using the uberjar like it's quick make, and save it only for the end of the day.

我在建立时使用lein uberjar时注意到的另一件事情是,小图形用户界面应用程序我正在编译过程中弹出框架,仿佛在编译时执行,它似乎有点违反直觉;它不像我所做的make思考。

Another thing I noticed while building (using lein uberjar) is that the small GUI app I am working on pops up frames in the compilation process, as if they are executing while compiling. It just seems a bit counterintuitive to me; it is not quite as analogous to "make" as I had thought.

我知道Lisp开发东西的方式是在REPL中交互地工作,我不想改变它:我想适应这种方式生活。不幸的是,我没有看到关于如何这样做的文档的形式。例如,如何重置机器的当前状态。

I know the Lisp way of developing things is interactively working in the REPL, and I am not trying to change that: I would like to adapt to this way of life. Unfortunately, I have seen little in the form of documentation on how to do so. For instance, how to reset the current state of the machine. It just seems kind of messy to just keep compiling individual snippets on the fly without being able to do some sort of reset.

我在Clojure(和Lisp)上看到的大多数教程都是这样的, )一般似乎集中在黑客的REPL。部署应用程序的最佳实践仍然是我的一个谜。我的用户只是用户;他们不会是将文件加载到REPL的开发人员。

Most tutorials I have seen on Clojure (and Lisp) in general seem to focus on hacking in the REPL. Best practices on the deployment of applications remains a mystery to me. My users are just going to be users; they are not going to be developers that are going to load files into a REPL.

这里是我的问题:任何资源的好信息或教程的整个过程构建一个Clojure应用程序,包括部署?

So here is my question: any resources for good information or tutorials on the entire process of building a Clojure application, including deployment?

(注意:我已经安装并运行所有必备软件(例如Emacs,Slime,Leiningen等),所以这不是一个问题。 / p>

(Note: I have all of the prerequisites installed and working (e.g. Emacs, Slime, Leiningen, etc.), so this is not a question about that).

推荐答案

一些快速提示,然后是一些链接:

A couple of quick hints, then some links:

在开发期间不使用 lein uberjar 喜欢 lein jar 。区别是 lein uberjar 将所有的依赖关系放在生成的 jar (包括Clojure本身)中, jar是一个完全自包含的包里面有你的应用程序; lein jar 只能保存您自己的代码。 uberjar 方法对部署有明显的好处,但是对于开发,您应该能够在运行应用程序时只使用适当的类路径,从而节省准备uberjar所需的时间。如果您不想手动管理测试运行的类路径,请查看 lein run 插件

Don't use lein uberjar during development; prefer lein jar. The difference is that lein uberjar puts all your dependencies in the generated jar (including Clojure itself), so that your single jar is an entirely self contained package with your app inside; lein jar only jars your own code. The uberjar approach has obvious benefits for deployment, but for development, you should be able to just use the appropriate classpath when running your app, saving yourself the time necessary to prepare an uberjar. If you don't want to hand-manage the classpath for test runs, check out the lein run plugin.

此外,大多数代码实际上不应该被AOT编译。 AOT在某些Java互操作场景中是必需的,但大多数时候它会带来启动速度的轻微提升以及与不同版本的Clojure的二进制兼容性的恼人问题。我想后一个问题与一个 uberjar -ed独立应用程序类型的项目无关,但任何库代码至少应该被保留为JIT-ed如果可能的话。使用Leiningen,您可以在 project.clj中的 defproject 表单中插入:namespaces 以确定要编译哪些命名空间;默认情况下,任何您遗漏的内容都将被JIT编辑。默认情况下,Leiningen的旧版本用于编译所有内容,这实际上是升级的好理由!

Also, most likely the majority of your code should not actually be AOT compiled. AOT is necessary in some Java interop scenarios, but most of the time it brings one a slight boost in startup speed and annoying problems with binary compatibility with different releases of Clojure. I suppose the latter issue is not relevant to an uberjar-ed standalone app kind of project, but any library code at least should be left to be JIT-ed if at all possible. With Leiningen, you can put a :namespaces clause in the defproject form in project.clj to determine which namespaces are to be compiled; whatever you leave out will currently be JIT-ed by default. Older versions of Leiningen used to compile everything by default, which is actually a good reason to upgrade!

至于在编译期间弹出的窗口,我猜你'在宏扩展时或在任何函数定义或类似构造之外运行窗口外弹出代码。 (像在顶层的一个(printlnFoo!))这只是你不应该做的,我想 - 除非你打算运行代码作为脚本,反正。为了避免这个问题,将副作用代码放在函数定义中,并使用 project.clj中的:main 。 (如果你说:main foo ,则 -main code>命名空间将被用作你的应用程序的入口点,这是默认的,反正至少上面提到的 lein run 似乎有硬编码的名称 - 不知道lein本身。)

As for the windows popping out during compilation, I would guess that you're either running window-out-popping code during macro expansion time or outside of any function definition or similar construct. (Something like a (println "Foo!") at the top level.) That's just something you shouldn't do, I suppose -- unless you are planning to run your code as a script, anyway. To avoid the problem, wrap side-effecting code up in function definitions and provide an entry point to your application using the :main clause in project.clj. (If you say :main foo, then the -main function from the foo namespace will be used as the entry point to your app. That's the default, anyway, and at least the above mentioned lein run seems to have the name hardcoded -- not sure about lein itself.)

对于重置REPL的状态 - 你可以重新启动它。有了SLIME,Mx slime-restart-inferior-lisp就能做到这一点,同时保持Emacs会话的所有其他状态。

As for resetting the state of the REPL -- you can just restart it. With SLIME, M-x slime-restart-inferior-lisp will do just that while maintaining all other state of your Emacs session.

另请参见Clojure Google组中的这些讨论:

See also these discussions on the Clojure Google group:


  1. Clojure for system administration

  2. 预填包装clojure(was:Re:Clojure for system administration)

  3. Leiningen,Clojure和libraries:我缺少什么?

  1. Clojure for system administration
  2. Prepping clojure for packaging (was: Re: Clojure for system administration)
  3. Leiningen, Clojure and libraries: what am I missing?

这篇关于构建和部署Clojure应用程序的最佳实践:好的教程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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