gpt4 book ai didi

jar - Clojure Uberjar 不加载资源文件

转载 作者:行者123 更新时间:2023-12-04 13:22:40 25 4
gpt4 key购买 nike

我使用 lein uberjar 创建应用程序的独立 jar。

执行时

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

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

我通过以下方式加载文件:
(ns dataloader.configuration
(:gen-class)
(:require [cheshire.core :refer :all]
[clojure.java.io :as io]))

(def data-file
(io/file
(io/resource "configuration.json")))

项目.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 放到jar的根目录下

最佳答案

如果您想阅读 configuration.json 的内容文件,请勿调用io/file .相反,请使用 slurp函数,像这样:

(def config (slurp (io/resource "configuration.json")))

关于jar - Clojure Uberjar 不加载资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32232662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com