This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-19
Channels
- # aleph (1)
- # announcements (3)
- # aws (1)
- # beginners (95)
- # calva (15)
- # clojars (4)
- # clojure (84)
- # clojure-android (3)
- # clojure-austin (1)
- # clojure-chicago (1)
- # clojure-dev (66)
- # clojure-europe (3)
- # clojure-italy (15)
- # clojure-nl (13)
- # clojure-uk (33)
- # clojuredesign-podcast (9)
- # clojurescript (6)
- # cursive (68)
- # data-science (4)
- # datavis (1)
- # datomic (13)
- # emacs (4)
- # fulcro (2)
- # jobs (4)
- # jobs-discuss (89)
- # luminus (23)
- # nrepl (6)
- # off-topic (2)
- # onyx (2)
- # pathom (4)
- # pedestal (11)
- # re-frame (9)
- # reagent (8)
- # reitit (5)
- # shadow-cljs (131)
- # spacemacs (13)
- # sql (8)
- # vim (8)
- # xtdb (7)
- # yada (4)
hi I'm currently working through a number of issues with a project that is acting very differently when compiled. One issue is that I have a route that I send a GET request to with a folder name as the :params. In dev mode it returns a list of strings that are the name of files inside that folder as an array. However once I compile the the project I get back an empty array. the route looks like this
["/folder-files" {:get (fn [] (let [folder (:img (:params ))] (response/ok (->> folder http://clojure.java.io/file file-seq (filter #(.isFile %)) (map #(.getName %)))) )) }] n.b there are single underscores as inputs in the project but they are being formatted out, also I'm still using immutant for now, thanks!
could it be to do with the path inside the jar? In the request I pass "resources/public/img" + a key to the folder name
@jcb when you use it like this, you assume that the resources
folder is directly in the folder where you run the JAR.
When you build an uberjar, resources folder isn't really there, but all its content is directly at the root of the jar.
However, even if the resources folder was there you wouldn't be able to use
ok, thanks, that interesting. I was really hoping to create a list of files in a folder whereas that seems to rely on being given a specific file name
I am missing a few pieces - http://clojure-doc.org/articles/cookbooks/files_and_directories.html#get-a-list-of-the-files-and-dirs-in-a-given-directory - uses io/file for this purpose
Yes, that's correct as long as those files are somewhere on the file system.
You could also wrap io/resource
with io/file
: (io/file (io/resource "myresource.txt"))
(EDIT: that might not work ...)
that's my problem, I don't have the file names yet. I want to create a list of files within a given directory. apologies if I'm missing something obvious, I appreciate the help
Yeah, I know 🙂. silly example - I meant that myresource.txt
could also be a folder or whatever.
It seems that io/file doesn't play well with io/resource; especially if it's a folder you want to list with file-seq
😞
I couldn't find anything better than this: https://stackoverflow.com/questions/23139331/how-to-get-list-of-classpath-resources-in-nested-jar
I was considering this https://github.com/xsc/cpath-clj but it seems untested beyond jdk8
I'm on it, however reading the source it seems to be doing something very similar with io/file anyway
is this really such an odd thing to be doing? I would have thought it would come up more often
I guess "listing a dir" is uncommon - people usually refer to a file which should work fine
cpath isn't a magic bullet - java.lang.IllegalArgumentException: No implementation of method: :child-resources of protocol: #'cpath-clj.core/ResourceLookup found for class: nil