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

查看:111
本文介绍了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)从类路径获取文件。经过一点挖掘,这似乎是适用于我的情况的解决方案:

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天全站免登陆