What does ":resource-paths" in leiningen do?

6,115 views
Skip to first unread message

larry google groups

unread,
Sep 10, 2012, 2:24:25 AM9/10/12
to clo...@googlegroups.com
I am looking here:


I see this:

:resource-paths
["src/main/resource"] ; non-code files included in classpath/jar

I am confused in 2 ways:

1.) is this a break from java conventions? I thought Java projects tended to put a "resources" folder at the top level of a project, rather than inside of src?

2.) how does this work? If I need a static resource compiled with my code then I need to do something like (clojure.java.io/resource "homepage.html"), yes? Does Leiningen actually compile in all static resources for me, if they are on the correct path?




Michael Klishin

unread,
Sep 10, 2012, 2:48:59 AM9/10/12
to clo...@googlegroups.com


2012/9/10 larry google groups <lawrenc...@gmail.com>


1.) is this a break from java conventions? I thought Java projects tended to put a "resources" folder at the top level of a project, rather than inside of src?


Different projects in the Java ecosystem tend to place resources into different places, e.g. Web app containers vs standalone apps vs giant ecosystems such as Eclipse. Leinigen lets use follow whatever convention you want.
 
2.) how does this work? If I need a static resource compiled with my code then I need to do something like (clojure.java.io/resource "homepage.html"), yes? Does Leiningen actually compile in all static resources for me, if they are on the correct path?

Leiningen will include them in the JAR produced by `lein jar` or `lein uberjar`  and at runtime they will be on classpath, so clojure.java.io/resource will be able
to locate them. You can also use paths relative to the root. They are not "compiled" in any other way, just included
as is.
--
MK

Phil Hagelberg

unread,
Sep 10, 2012, 12:05:03 PM9/10/12
to clo...@googlegroups.com
larry google groups <lawrenc...@gmail.com> writes:

> I see this:
>
> :resource-paths ["src/main/resource"] ; non-code files included in
> classpath/jar
>
> I am confused in 2 ways:
>
> 1.) is this a break from java conventions? I thought Java projects
> tended to put a "resources" folder at the top level of a project,
> rather than inside of src?

The top-level resources/ is what you get by default; the sample
project.clj file just shows you what it would look like if you were to
change it. Personally I'm not a fan of the paid-by-the-directory deep
nesting approach, but it's shown there because it's the only other
common convention. =)

-Phil

Murtaza Husain

unread,
Sep 13, 2012, 6:02:08 AM9/13/12
to clo...@googlegroups.com

A good use case - You want to place html files, that can be processed in your server side code. Inorder for your code to have access to it, you will have to place them in the src dir. However if you use the :resource-path, you can define a dir relative to the root of your project where you are placing your html files. 

I recently used them to place my html files in resource/public/templates folder, when using enlive for processing html files. 

Chris Kuttruff

unread,
Jul 5, 2014, 1:35:47 PM7/5/14
to clo...@googlegroups.com
So if you have an arbitrary number of files in said resources directory, is there a good way to find all files underneath a certain resource path?
if I have "resources/foo.txt" and "resources/bar.txt", what function would I use to exact both names of the txt files I have?

Thanks in advance,
-Chris
Reply all
Reply to author
Forward
0 new messages