Same behaviour with 2.14
1 of 1 people found this helpful
Add your resources in the same folder structure as the Java class that will consume it and use getClass().getResource() to retrieve a URL instance out of it:
URL url = getClass().getResource("voila.txt");
Resource<?> resource = resourceFactory.create(url);
Tip: Using FileResource directly in your addon is a bad practice, as it relies on the physical file. The best would be to use Resource<?>. This makes your code unaware of the resource location.
Indeed there is no need to use File or FileResource even if its a file after all (I'm a disciple of intuitive programming ).
That leads to a problem (project root appended before an ok full file path). (should I create a TestCase ?)
Resource<URL> templateResource = rfactory.create(getClass().getResource("voila.txt"));
brings null in templateResource although this syntax is used in the angular-js addon for example (FreemarkerClientTest.java)
For future reference, a working code is :
Resource<URL> templateResource = rfactory.create(getClass().getClassLoader().getResource("voila.txt")); Template template = tfactory.create(templateResource, FreemarkerTemplate.class);
I'm using Java 7.0.40 on w7 64 and it works on my machine, today
As I plan to have a quantity of templates I prefer to put them in resources, separated from java sources.
I'll file an improvement request about that because what's the point of having the maven tree if a part of it is not used by default.