title: Loading a configuration file from the classpath
body: <p>I'm working on making my Java app easy to deploy to other computers and am writing an ant script to do so, that is going fine.</p>
  
  <p>I'm having trouble loading resources that are listed in the classpath named in the manifest file of the jar.</p>
  
  <p>Folder structure looks like this:</p>
  
  <pre><code>/MyProgram.jar
  /lib/&lt;dependencies&gt;
  /config/configuration.xml
  </code></pre>
  
  <p>I can not for the life of me access the configuration.xml file using the ClassLoader. It, along with all the dependencies are listed explicitly in the Class-Path entry to the manifest file.</p>
  
  <p>I've tried many variants of the following:</p>
  
  <pre><code>this.xml = Thread.currentThread().getContextClassLoader()
                   .getResourceAsStream(xmlName);
  
  this.xml = this.getClass().getResourceAsStream(xmlName);
  </code></pre>
  
  <p>With xmlName as a string of all the following values:</p>
  
  <pre><code>"config/configuration.xml"
  "configuration.xml"
  "config.configuration.xml"
  </code></pre>
  
  <p>Related to this, I also have a log4j.properties file in the config directory. How do I get log4j to pick it up? Other references say it just needs to be in the classpath, and it too is explicitly named in the jar's manifest file. Can someone point me in the right direction?</p>
  
  <p>Update:</p>
  
  <p>Here are the actual entries from Class-Path:</p>
  
  <pre><code>Class-Path: &lt;snip dependencies&gt; config/configuration.xml config/log4j.properties
  </code></pre>