title: Java - How to access a file in the WEB-INF folder WITHOUT servlet context
body: <p>I have a central class (<code>RuntimeConfiguration</code>) that holds around <code>100</code> parameters for my application. These parameters are taken from an <em>XML file</em> which I stored in the <code>WEB-INF</code> folder. On my development box, I hard-coded the path, but for very obvious reasons, this is not a productive solution.</p>
  <p>For portability reasons (my application might be executed on a <em>Tomcat</em> or a <em>Jetty</em> and under Windows OR Unix), I want to have a generic access way to this file from within my <code>RuntimeConfiguration</code> class.</p>
  <p>I know, I can use <code>getRealPath</code> in case I have a servlet, BUT <code>RuntimeConfiguration</code> is NOT started within a <em>servlet context</em>. It is invoked from a job (a crawler) which in turn is started from quartz job control via <code>applicationContext.xml</code>. Now this seems to be the core of my problem.</p>
  <p>Can anyone tell me, how to get the absolute path to my XML in this environment?</p>
  <p>I tried this <code>ClassLoader</code> approach, but it gives me a <code>NullPointerException</code>:</p>
  <pre><code>ClassLoader loader = this.getClass().getClassLoader();
  loader.getResource(&quot;WEB-INF&quot;);
  result = loader.getSystemResource(RTCF).toString(); 
  </code></pre>
  <p>I also tried</p>
  <pre><code>URL url = this.getClass().getClassLoader().getResource(&quot;WEB-INF&quot;);
  </code></pre>
  <p>which also throws a null pointer exception</p>
  <p>Can anyone give me a portable solution, one that works on my dev-machine and on a production system where my application is deployed as a WAR-file?</p>
  <p>By the way, the method should at best be able to handle Windows AND Mac OS X / Unix based systems.</p>