Clojure Uberjar does not load resource file

I am using lein uberjar to create a standalone jar of application.

While doing

java -jar dataloader-0.1.0-SNAPSHOT-standalone.jar, 

failure:

 Caused by: java.lang.IllegalArgumentException: Not a file: jar:file:dataloader-0.1.0-SNAPSHOT-standalone.jar!/configuration.json 

I upload the file via:

 (ns dataloader.configuration (:gen-class) (:require [cheshire.core :refer :all] [clojure.java.io :as io])) (def data-file (io/file (io/resource "configuration.json"))) 

project.clj

 (defproject dataloader "0.1.0-SNAPSHOT" :description "Used for loading stage data into local vagrantbox" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :resource-paths ["resources"] :dependencies [[org.clojure/clojure "1.6.0"] [clojurewerkz/elastisch "2.1.0"] [org.clojure/java.jdbc "0.3.7"] [mysql/mysql-connector-java "5.1.32"] [clj-http "2.0.0"] [org.clojure/data.json "0.2.6"] [org.clojure/data.codec "0.1.0"] [cheshire "5.5.0"]] :main ^:skip-aot dataloader.core :target-path "target/%s" :profiles {:uberjar {:aot :all}}) 

resources / configuration.json is placed in the root jar folder

+5
jar resources clojure uberjar leiningen
Aug 26 '15 at 17:10
source share
2 answers

clojure.java.io/resource returns a URL, not a file. That is why you can call it slurp . The error message tells you that this is not a file, unfortunately, it does not tell you that it is a URL.

Of course, you can open the URL with java.net.URL api, although in this case it will be redundant.

+10
Aug 26 '15 at 22:30
source share

If you want to read the contents of the configuration.json file, do not call io/file . Use the slurp function instead, for example:

 (def config (slurp (io/resource "configuration.json"))) 
+4
Aug 26 '15 at
source share



All Articles