如何在 Clojure 中停止 jetty 服务器?
我正在使用ring 和clojure 编写一个Web 应用程序。我使用 jetty 适配器作为开发服务器,使用 emacs/SLIME 作为 IDE。虽然wrap-reload确实有帮助,但run-jetty会阻止我的slime会话,我希望能够随意启动/停止它,而不必在单独的终端会话中运行它。理想情况下,我想定义一个服务器代理和启动服务器和停止服务器函数,以启动/停止代理内的服务器。这可能吗?
I am writing a web application using ring and clojure. I am using the jetty adapter for the development server and emacs/SLIME for IDE. While wrap-reload does help, run-jetty blocks my slime session and I would like to be able to start/stop it at will without having to run it in a separate terminal session. Ideally, I would like to define a server agent and functions start-server and stop-server that would start/stop the server inside the agent. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的 Ring 应用程序中通常有一行,如下所示:
这可以防止锁定 REPL。它还允许我重新编译该文件,而不必担心我的服务器将被重新定义。它还允许您在 REPL 上进行交互,如下所示
:
I usually have a line in my Ring app that looks like the following:
This prevents locking up the REPL. It also allows me to recompile this file without worrying that my server will get redefined. It also lets you interact at the REPL like so:
and
Jetty 文档包含一些有关 Jetty 正常关闭的信息。这可能还不够,但它可以帮助您入门。
我还没有开始使用 compojure,但总的来说我更喜欢使用 Tomcat。功能更加全面;除此之外,还有一个记录良好的 API 用于启动和关闭它,它在专用端口上侦听关闭命令;有
ant
任务可以执行此操作,当然也可以从 Java 应用程序调用它们。我只是不知道 Compojure 将 REPL 连接到正在运行的 Web 容器实例有什么样的魔力,以及自动类重新加载是否/如何发生......希望其他人能够提供更多信息。The Jetty documentation has some information on graceful shutdown of Jetty. That's probably not enough information but it may get you started.
I haven't started playing with compojure yet, but overall I prefer to work with Tomcat. It's more full-featured; among other things, there is a well-documented API for starting it up and shutting it down, it listens for the shutdown command on a dedicated port; there are
ant
tasks to do this, and they could of course be called from a Java app as well. I just don't know what kind of magic Compojure does with connecting the REPL to a running instance of the Web container, and if/how automatic class reloading happens... hopefully someone else will be able to provide more information.12年后。
VSCode / Calva:
如果你像我一样从 VSCode / Calva 内的 repl 启动 jetty
您必须在终端上按 CTRL-C 键而不是 REPL 的服务器进程。
事实上,服务器进程绑定到终端而不是 REPL。
12 years later.
VSCode / Calva:
If you are like me starting jetty from the repl inside VSCode / Calva
you have to CTRL-C the server process at the terminal not the REPL.
In fact the server process is bound to the terminal not to the REPL.