Robert Zaremba
Robert Zaremba

Reputation: 8481

How to use `clojure --main`

When reading clojure -h* I found the --main option:

  main options:
    -m, --main ns-name  Call the -main function from a namespace with args

Having the following code:

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

Is it possible to utilize the --main argument to call directly the -main function without using lein?

*clojure = java ${JAVA_OPTS} -jar path_to_clojure.jar "$@"

Upvotes: 2

Views: 556

Answers (1)

Alex Filatov
Alex Filatov

Reputation: 5052

Yes. Assuming -main function is in the file ./src/foo/core.clj the following will run it:

java -cp "path_to_clojure.jar:src" clojure.main --main foo.core (note the src in the classpath)

Upvotes: 1

Related Questions