Running a Clojure script from an Uberjar
I normally deploy Clojure web applications by packaging them then up into an uberjar with lein uberjar
, copying the jar to the server and running it with:
java -jar my-app-standalone.jar
Recently I had a script that I wanted to run on a periodic basis on the server too (indexing data into Elastic Search).
It wasn’t clear to me at first how I could package the script up into the same uberjar and call it on the server.
With a bit of help from the Clojurians, I found I could write a script as follows:
(ns my-app.scripts.my-script)
(defn -main []
(println "This is my script"))
And run it from the uberjar with:
java -cp my-app-standalone.jar clojure.main -m my-app.scripts.my-script
👍