Skip to content

Instantly share code, notes, and snippets.

Last active October 15, 2019 07:32
What would you like to do?
Simple Clojure "Hello world" using leiningen

Blog 2019/7/17

<- previous | index | next ->

Simple Clojure "Hello world" using leiningen

Create a new single-file Clojure project using the main template (thanks to Ming Pan):

$ lein new main hello
$ cd hello

Run it:

$ lein run

Or start a REPL:

$ lein repl

and then execute the main function by typing (-main) into the REPL.


You can also create a simple Dockerfile:

FROM clojure
COPY . /root
CMD ["lein", "run"]

Build it:

$ docker build -t hello .

Run it:

$ docker run hello

You can speed this up a bit by generating an uberjar (thanks to Divyum Rastogi):

FROM clojure
COPY . /root
RUN mv "$(lein uberjar | sed -n 's/^Created \(.*standalone\.jar\)/\1/p')" app-standalone.jar
CMD ["java", "-jar", "app-standalone.jar"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment