Clojure 应用程序中的资源 [英] Resources in Clojure applications

查看:25
本文介绍了Clojure 应用程序中的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 Clojure 项目(一个 GUI 应用程序)中使用 Leiningen,并在项目根目录下创建了一个资源"目录来保存我的应用程序使用的图像.

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.

当我在测试期间在本地运行我的应用程序时,我使用相对路径resources/logo.png"获取图像,这工作正常.但是当我使用 Leiningen 构建 uberjar 时,Leiningen 将资源文件夹中的文件放在 JAR 的根文件夹中,因此我对资源文件的引用不再起作用.

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.

使用 Leiningen 访问此类资源的正确方法是什么?

What is the correct way to access resources like this using Leiningen?

推荐答案

之前的回答者 (skuro) 指出我需要从 classpath 中获取文件.经过更多的挖掘,这似乎是适用于我的案例的解决方案:

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"))

这篇关于Clojure 应用程序中的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆