I've created a sample project at Github[1] to demonstrate the problem I'm facing with accessing a resource file when using an uberjar. Could someone point out what I'm doing wrong here? Thanks!
[1]: https://github.com/RasterBurn/halp
### Given this code: ############### ```clojure (ns halp.core (:require [clojure.java.io :as io]) (:gen-class)) (defn -main "I don't do a whole lot ... yet." [& args] (-> "hi.txt" io/resource io/file (io/copy *out*))) ``` ### It runs well under leiningen ####### ``` ➜ halp lein run . ─────────▄──────────────▄ ────────▌▒█───────────▄▀▒▌ ────────▌▒▒▀▄───────▄▀▒▒▒▐ ───────▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐ ─────▄▄▀▒▒▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐ ───▄▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀██▀▒▌ ──▐▒▒▒▄▄▄▒▒▒▒▒▒▒▒▒▒▒▒▒▀▄▒▒▌ ──▌▒▒▐▄█▀▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐ ─▐▒▒▒▒▒▒▒▒▒▒▒▌██▀▒▒▒▒▒▒▒▒▀▄▌ ─▌▒▀▄██▄▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▌ ─▌▀▐▄█▄█▌▄▒▀▒▒▒▒▒▒░░░░░░▒▒▒▐ ▐▒▀▐▀▐▀▒▒▄▄▒▄▒▒▒▒▒░░░░░░▒▒▒▒▌ ▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒░░░░░░▒▒▒▐ ─▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒▒▒░░░░▒▒▒▒▌ ─▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐ ──▀▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▒▒▒▒▌ ────▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀ ───▐▀▒▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀ ──▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▀ ``` ### But not so much as an uberjar ######### ``` ➜ halp java -jar target/uberjar/halp-0.1.0-SNAPSHOT-standalone.jar Exception in thread "main" java.lang.IllegalArgumentException: Not a file: jar:file:/home/vagrant/code/halp/target/uberjar/halp-0.1.0-SNAPSHOT-standalone.jar!/hi.txt at clojure.java.io$fn__8588.invoke(io.clj:63) at clojure.java.io$fn__8572$G__8556__8577.invoke(io.clj:35) at clojure.java.io$file.invoke(io.clj:414) at halp.core$_main.doInvoke(core.clj:11) at clojure.lang.RestFn.invoke(RestFn.java:397) at clojure.lang.AFn.applyToHelper(AFn.java:152) at clojure.lang.RestFn.applyTo(RestFn.java:132) at halp.core.main(Unknown Source) ```
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
io/file
--
(if (= "file" (.getProtocol u)) (as-file (escaped-utf8-urlstring->str (.replace (.getFile u) \/ File/separatorChar))) (throw (IllegalArgumentException. (str "Not a file: " u)))))
When running from the repl, .getProtocol returns "file", but when running from an uberjar, .getProtocol returns "jar".