diff --git a/script/compile b/script/compile index 4379c3ac..35b14bb5 100755 --- a/script/compile +++ b/script/compile @@ -46,7 +46,7 @@ args=( "-jar" "$BABASHKA_JAR" "--initialize-at-run-time=java.lang.Math\$RandomNumberGeneratorHolder" "--initialize-at-build-time" "-H:Log=registerResource:" - "-H:EnableURLProtocols=http,https" + "-H:EnableURLProtocols=http,https,jar" "--enable-all-security-services" "-H:+JNI" "--verbose" diff --git a/src/babashka/main.clj b/src/babashka/main.clj index d52cde29..b5ee79f6 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -497,9 +497,8 @@ 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] - (try (cp/getResource loader [path] {:url? true}) - ;; non-relative paths don't work - (catch Exception _e nil))))) + (if (str/starts-with? path "/") nil ;; non-relative paths always return nil + (cp/getResource loader [path] {:url? true}))))) (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 b4a8a960..0de24ed1 100644 --- a/test/babashka/classpath_test.clj +++ b/test/babashka/classpath_test.clj @@ -57,4 +57,9 @@ (is (= (.length (io/file "logo" "icon.png")) (.length tmp-file)))) (testing "No exception on absolute path" - (is (nil? (bb nil "(io/resource \"/tmp\")"))))) + (is (nil? (bb nil "(io/resource \"/tmp\")")))) + (testing "Reading a resource from a .jar file" + (is (= "true" + (str/trim + (tu/bb nil "--classpath" "test-resources/babashka/src_for_classpath_test/foo.jar" + "(pos? (count (slurp (io/resource \"foo.clj\")))) "))))))