Add -jar option to run uberjar
This commit is contained in:
parent
02032625ee
commit
916858e016
2 changed files with 24 additions and 3 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
(ns babashka.impl.classpath
|
(ns babashka.impl.classpath
|
||||||
{:no-doc true}
|
{:no-doc true}
|
||||||
(:require [clojure.java.io :as io]
|
(:require [babashka.impl.clojure.main :refer [demunge]]
|
||||||
|
[clojure.java.io :as io]
|
||||||
[clojure.string :as str])
|
[clojure.string :as str])
|
||||||
(:import [java.util.jar JarFile]))
|
(:import [java.util.jar JarFile Manifest]))
|
||||||
|
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
|
|
@ -68,6 +69,12 @@
|
||||||
resource-paths (mapv #(str base-path %) [".bb" ".clj" ".cljc"])]
|
resource-paths (mapv #(str base-path %) [".bb" ".clj" ".cljc"])]
|
||||||
(getResource loader resource-paths opts)))
|
(getResource loader resource-paths opts)))
|
||||||
|
|
||||||
|
(defn main-ns [manifest-resource]
|
||||||
|
(some-> (Manifest. (io/input-stream manifest-resource))
|
||||||
|
(.getMainAttributes)
|
||||||
|
(.getValue "Main-Class")
|
||||||
|
(demunge)))
|
||||||
|
|
||||||
;;;; Scratch
|
;;;; Scratch
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,11 @@
|
||||||
(recur (next options)
|
(recur (next options)
|
||||||
(assoc opts-map
|
(assoc opts-map
|
||||||
:file (first options))))
|
:file (first options))))
|
||||||
|
("--jar" "-jar")
|
||||||
|
(let [options (next options)]
|
||||||
|
(recur (next options)
|
||||||
|
(assoc opts-map
|
||||||
|
:jar (first options))))
|
||||||
("--repl")
|
("--repl")
|
||||||
(let [options (next options)]
|
(let [options (next options)]
|
||||||
(recur (next options)
|
(recur (next options)
|
||||||
|
|
@ -456,7 +461,8 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
||||||
:expressions :stream?
|
:expressions :stream?
|
||||||
:repl :socket-repl :nrepl
|
:repl :socket-repl :nrepl
|
||||||
:verbose? :classpath
|
:verbose? :classpath
|
||||||
:main :uberscript :describe?] :as _opts}
|
:main :uberscript :describe?
|
||||||
|
:jar] :as _opts}
|
||||||
(parse-opts args)
|
(parse-opts args)
|
||||||
_ (do ;; set properties
|
_ (do ;; set properties
|
||||||
(when main (System/setProperty "babashka.main" main))
|
(when main (System/setProperty "babashka.main" main))
|
||||||
|
|
@ -480,6 +486,8 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
||||||
(System/getenv "BABASHKA_CLASSPATH"))
|
(System/getenv "BABASHKA_CLASSPATH"))
|
||||||
_ (when classpath
|
_ (when classpath
|
||||||
(add-classpath* classpath))
|
(add-classpath* classpath))
|
||||||
|
_ (when jar
|
||||||
|
(add-classpath* jar))
|
||||||
load-fn (fn [{:keys [:namespace :reload]}]
|
load-fn (fn [{:keys [:namespace :reload]}]
|
||||||
(when-let [{:keys [:loader]}
|
(when-let [{:keys [:loader]}
|
||||||
@cp-state]
|
@cp-state]
|
||||||
|
|
@ -496,6 +504,12 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
||||||
(let [abs-path (.getAbsolutePath (io/file file))]
|
(let [abs-path (.getAbsolutePath (io/file file))]
|
||||||
(vars/bindRoot sci/file abs-path)
|
(vars/bindRoot sci/file abs-path)
|
||||||
(System/setProperty "babashka.file" abs-path)))
|
(System/setProperty "babashka.file" abs-path)))
|
||||||
|
main (if (and jar (not main))
|
||||||
|
(when-let [res (cp/getResource
|
||||||
|
(:loader @cp-state)
|
||||||
|
["META-INF/MANIFEST.MF"] {:url? true})]
|
||||||
|
(cp/main-ns res))
|
||||||
|
main)
|
||||||
;; TODO: pull more of these values to compile time
|
;; TODO: pull more of these values to compile time
|
||||||
opts {:aliases aliases
|
opts {:aliases aliases
|
||||||
:namespaces (-> namespaces
|
:namespaces (-> namespaces
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue