Skip to content
Mr. Foo Bar (‸‶ edited this page May 24, 2015 · 19 revisions

It's possible to create self-contained, executable Clojure scripts that can bring in Maven dependencies, using a shebang. Here is an example that runs a game like Lunar Lander:

Put this into a file called lunarlander:

#!/usr/bin/env boot

(set-env! :dependencies '[[alandipert/hyperturbo "0.0.1-SNAPSHOT"]])
(require '[alandipert.hyperturbo.lunar-lander :refer [run]])

(defn -main [& args]
  (run))

NOTE: Github wiki's syntax formatting is messed up and eats single quotes sometimes. The vector passed to set-env! above should be quoted.

Make the file executable:

chmod +x lunarlander

Run the script:

./lunarlander

Command-line args

If you define a -main function, it will be called and passed any command-line arguments.

(defn -main [& args]
  ...)

You can use Boot's built-in arg specification macro to get parsing of named args and automatic --help generation as well:

(require '[boot.cli :refer [defclifn]])

(defclifn -main
  [a awesome bool "Whether you want this app to be awesome or not. (Default true)"]
  ...)

Calling boot tasks from the script

 (boot (some-task))
Clone this wiki locally