I am using Leiningen in my Clojure project (a GUI application) and created a "resources" directory under the project root to hold images that my app uses.
When I am running my app locally during testing, I fetch the images using the relative path "resources/logo.png", and this works fine. But when I build an uberjar using Leiningen, Leiningen puts the files from the resources folder in the JAR's root folder, so my references to resource files don't work anymore.
What is the correct way to access resources like this using Leiningen?
Clojure Overview. Clojure is a dynamically-typed, functional programming language that runs on the JVM (Java 5 or greater) and provides interoperability with Java. A major goal of the language is to make it easier to implement applications that access data from multiple threads (concurrency).
Clojure (still) for Start-ups While more large companies are adopting Clojure than ever, the sweet spot is still the smaller companies of less than 100 employees. The reasons that start-ups choose Clojure are many and variegated: Leverage - small effort, big result.
Clojure is designed to be a hosted language, sharing the JVM type system, GC, threads etc. All functions are compiled to JVM bytecode. Clojure is a great Java library consumer, offering the dot-target-member notation for calls to Java. Clojure supports the dynamic implementation of Java interfaces and classes.
A Clojure REPL (standing for Read-Eval-Print Loop) is a programming environment which enables the programmer to interact with a running Clojure program and modify it, by evaluating one code expression at a time.
The previous answerer (skuro) pointed out that I need to get the file from the classpath. After a little more digging, this appears to be the solution that works for my case:
(.getFile (clojure.java.io/resource "foo.png"))
Just a syntax sugar for the answer of Kevin Albrecht:
(require '[clojure.java.io :as io]) (-> "foo.png" io/resource io/file)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With