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
|
||||
{: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])
|
||||
(:import [java.util.jar JarFile]))
|
||||
(:import [java.util.jar JarFile Manifest]))
|
||||
|
||||
(set! *warn-on-reflection* true)
|
||||
|
||||
|
|
@ -68,6 +69,12 @@
|
|||
resource-paths (mapv #(str base-path %) [".bb" ".clj" ".cljc"])]
|
||||
(getResource loader resource-paths opts)))
|
||||
|
||||
(defn main-ns [manifest-resource]
|
||||
(some-> (Manifest. (io/input-stream manifest-resource))
|
||||
(.getMainAttributes)
|
||||
(.getValue "Main-Class")
|
||||
(demunge)))
|
||||
|
||||
;;;; Scratch
|
||||
|
||||
(comment
|
||||
|
|
|
|||
|
|
@ -148,6 +148,11 @@
|
|||
(recur (next options)
|
||||
(assoc opts-map
|
||||
:file (first options))))
|
||||
("--jar" "-jar")
|
||||
(let [options (next options)]
|
||||
(recur (next options)
|
||||
(assoc opts-map
|
||||
:jar (first options))))
|
||||
("--repl")
|
||||
(let [options (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?
|
||||
:repl :socket-repl :nrepl
|
||||
:verbose? :classpath
|
||||
:main :uberscript :describe?] :as _opts}
|
||||
:main :uberscript :describe?
|
||||
:jar] :as _opts}
|
||||
(parse-opts args)
|
||||
_ (do ;; set properties
|
||||
(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"))
|
||||
_ (when classpath
|
||||
(add-classpath* classpath))
|
||||
_ (when jar
|
||||
(add-classpath* jar))
|
||||
load-fn (fn [{:keys [:namespace :reload]}]
|
||||
(when-let [{:keys [:loader]}
|
||||
@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))]
|
||||
(vars/bindRoot sci/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
|
||||
opts {:aliases aliases
|
||||
:namespaces (-> namespaces
|
||||
|
|
|
|||
Loading…
Reference in a new issue