diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 4afe6e32..f338965f 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -481,7 +481,9 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that (assoc-in ['clojure.java.io 'resource] (fn [path] (when-let [{:keys [:loader]} @cp-state] - (cp/getResource loader [path] {:url? true})))) + (try (cp/getResource loader [path] {:url? true}) + ;; non-relative paths don't work + (catch Exception _e nil))))) (assoc-in ['user (with-meta '*input* (when-not stream? {:sci.impl/deref! true}))] input-var) diff --git a/test/babashka/classpath_test.clj b/test/babashka/classpath_test.clj index c03ade13..b4a8a960 100644 --- a/test/babashka/classpath_test.clj +++ b/test/babashka/classpath_test.clj @@ -55,4 +55,6 @@ (.deleteOnExit tmp-file) (bb nil "--classpath" "logo" "-e" (format "(io/copy (io/input-stream (io/resource \"icon.png\")) (io/file \"%s\"))" (.getPath tmp-file))) (is (= (.length (io/file "logo" "icon.png")) - (.length tmp-file))))) + (.length tmp-file)))) + (testing "No exception on absolute path" + (is (nil? (bb nil "(io/resource \"/tmp\")")))))