Quantcast

How should I load a file from the classpath?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How should I load a file from the classpath?

BorisA
This post has NOT been accepted by the mailing list yet.
I have a file named Entry.template which I would like to load from the Classpath.
The Entry.template file is copied to .grails/.../resources. I believe the 'resources' directory is supposed to be on the Classpath?

My GrailsTestCase class has the following:

Resource resource = new ClassPathResource("resources/Entry.template")
def template = resource.getFile()


The Citation.template file is not found:

class path resource [resources/Entry.template] cannot be resolved to URL because it does not exist

Does any one know what I'm doing wrong? The approach I've used is supposed to work according to this blog post: http://phatness.com/2010/02/grails-test-files/

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How should I load a file from the classpath?

BorisA
This post has NOT been accepted by the mailing list yet.
Well I kinda figured it out by doing this;

def templateFile = getClass().classLoader.rootLoader.getResource("com/f1000/etoc/Entry.template").openStream()

Feels like quite an ugly way to get the file from the Classpath, some one must know of a groovier way?
Loading...