Frage

Ich schreibe eine Web-Anwendung mit Ring und Clojure. Ich bin mit dem Anlegesteg-Adapter für den Entwicklungs-Server und Emacs / SLIME für IDE. Während Wrap-Reload-Hilfe tut, Laufanlegesteg blockiert meinen Schleim Sitzung, und ich möchte in der Lage sein, es nach Belieben zu starten / stoppen, ohne dass es in einer separaten Terminal-Sitzung zu starten. Im Idealfall würde Ich mag einen Server-Agenten definieren, und die Funktionen Start-Server und Stop-Server, der die Server innerhalb der Agent würde starten / stoppen. Ist das möglich?

War es hilfreich?

Lösung

I usually have a line in my Ring app that looks like the following:

(defonce server (run-jetty #'my-app {:port 8080 :join? false}))

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:

user=> (.stop server)

and

user=> (.start server)

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top