For the past 6 months, I have been running my Clojure app from the repl.
Ie, whenever I want to run the app, I load up a clojure repl, then I type in: (load-file "src/run.clj") ... and it runs my app.
Then, clojure loads up all of my *.clj files, compiles them, and runs.
I have recently switched over to Lein. I would like to "compile ahead of time / package up" my code, so that I can get a single jar, with Main method, and run it directly on the command line via "java ..." rather than having to load up a clojure/lein repl.
It's clear to me that I need to do some RTFMing. However, if someone could point me at a good tutorial, it would be much appreciated.
Thanks!
There is also a nice tutorial in the official lein tutorial . I'm just including this information in case we end up with any dead links in the future.
1) You first need to designate the main namespace by adding :main
to project.clj
(defproject yourproject "0.1"
:dependencies [[org.clojure/clojure "1.4.0"]]
:main yourproject.core)
2) In your designated main namespace you must add (:gen-class)
and you must designate the main function by using (defn -main ...)
(ns yourproject.core
(:gen-class))
(defn -main [& args]
(println "This is your crazy project!"))
3) run uberjar
to create the standalone jar
lein uberjar
4) run your program with java -jar
java -jar yourproject.jar
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.