How to reference a file in the source dir from any Java code?
<p>Suppose I had a directory containing resource files stored somewhere within the "src" source directory, containing things like templates, config files, etc.</p>

<p>I'm aware that from a Servlet I can access files by name like:</p>

<p><code>File file = new File(ServletContact.getResource("some/namespace/filename.txt").getPath());</code></p>

<p>And from a non-Servlet I can do:</p>

<p><code>File file = new File(Object.class.getResource("some/namespace/filename.txt").getPath());</code></p>

<p>But the problem is that I have code that needs to access these resource files and can be run independent of the runtime environment.  e.g. Some code uses templates from within a servlet (under Tomcat 7).  Other code runs as a Quartz background job and works with templates.  If I try the <code>Object.class.getResource()</code> method in a Tomcat servlet, it returns null.</p>

<p>How can I access resources files in a safe way regardless of runtime environment, app engine, etc.?</p>
