I've never done that in Clojure, but another developer at the company
I work for made a java utility that allows you to refer to classpath
resources as URLs. It's on sourceforge in a package called "OpenHMS
Common Utilities":

http://openhms.sourceforge.net/common-util/

There's a class called
com.healthmarketscience.common.util.resource.Handler that, when
initialized, registers a "resource" URL handler. I think you should be
able to do something like:

;; Call the static init method on the Handler class to register the
resource: URL handler.
;; You just need to do this once before trying to use a resource URL
(. com.healthmarketscience.common.util.resource.Handler init)

;; Use resource:... URLs just like any other
(.openStream (new URL "resource:the/classpath/resource.txt"))

I use this in java code all the time. I've never tried it in Clojure,
but there's no reason it shouldn't work.

If you decide not to use that, then try something like:

 (.findResource (.getContextClassLoader (.currentThread Thread))
"your.resource.txt")



On Sat, Dec 20, 2008 at 6:12 AM, Darren Austin <darren.aus...@gmail.com> wrote:
>
> Hey folks,
>
> I am probably missing something obvious here, but is there an good way
> to open a resource file that is relative to the current class path?  I
> want to bundle up some data files with my .clj source in a .jar file.
> From the clojure code, I need to open these data files. I looked at
> Class.getResourceAsStream(), but I couldn't find a good way to get an
> object that would give me a Class object from the package/ns of my
> clojure code.  Any suggestions on how to achieve this?
>
> Thanks,
> --Darren
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to