You may find value in reading this:
From: 
http://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html

> Methods in the classes Class and ClassLoader provide a 
location-independent way to locate resources.

On Tuesday, January 27, 2015 at 9:12:23 AM UTC-5, Benjamin VanRyseghem 
wrote:
>
> The code can be found here: 
> https://github.com/teamwall/teamwall/blob/develop/src/server/teamwall/api.clj#L85
>
> Here I used to do something like `io/as-file path-to-my-file`
> but it failed because it’s not resolved as a file anymore when it’s jarred
>
> Good luck,
> Ben
>
>
>
>
> On Tue, Jan 27, 2015 at 2:00 PM, Dan Harbin <dan.h...@gmail.com 
> <javascript:>> wrote:
>
>> Ben, I would appreciate it if you'd show me the sample code.  Thanks for 
>> your help, everyone!
>>
>> On Tuesday, January 27, 2015 at 6:28:59 AM UTC-6, Benjamin VanRyseghem 
>> wrote:
>>>
>>> I face something similar.
>>>
>>> The issue was that inside a jar file, a resource is not a java.io.File 
>>> anymore.
>>>
>>> I could turn around using an InputStream (I was in the case I wanted to 
>>> serve a resource via http-kit)
>>>
>>> If you want more info, I can point you to the code where I use it
>>>
>>> Hope it helps,
>>> Ben
>>>
>>>
>>>
>>>
>>> On Tue, Jan 27, 2015 at 5:04 AM, Dan Harbin <dan.h...@gmail.com> wrote:
>>>
>>>> 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.
>>>>
>>>  
>>>  -- 
>> 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 
>> <javascript:>
>> 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 <javascript:>
>> 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 <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to