Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Document cross platform single file JVM launcher script #8

Open
borkdude opened this issue Nov 28, 2020 · 0 comments
Open

Document cross platform single file JVM launcher script #8

borkdude opened this issue Nov 28, 2020 · 0 comments

Comments

@borkdude
Copy link
Contributor

borkdude commented Nov 28, 2020

;; This should only be executed by babashka

(defmacro setup [& body]
  (when (System/getProperty "babashka.version")
    `(do ~@body)))

(setup
  (def deps '{:deps {clj-time {:mvn/version "0.14.2"}}})
  (require '[babashka.process :as p])
  (-> (p/process (into ["clojure" "-Sdeps" deps "-M" *file*] *command-line-args*)
                 {:inherit true})
      deref :exit (System/exit)))

;; JVM code only reachable from here

(println "Hello from the JVM!")
(println *clojure-version*)
(println *command-line-args*)
(require '[clj-time.core :as t])
(println (t/hour (t/now)))

Usage:

$ bb /tmp/xpclj.clj 1 2 3
Hello from the JVM!
{:major 1, :minor 10, :incremental 1, :qualifier nil}
(1 2 3)
19
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant