title: How do I load a properties file with JUnit / Ant?
body: <p>I'm using Ant 1.8, JUnit 4.8.2.  I'm trying to load a properties file and having some problems.  The properties file is at the root of my source directory and I load that into the classpath as well as explicitly loading the properties file in the classpath.  Below is my ant build.xml file.  Here is how I'm trying to load the properties …</p>
  
  <pre><code>private void loadTestProperties() { 
      try { 
          Properties prop = new Properties();
          InputStream in = getClass().getResourceAsStream("db.properties");
          prop.load(in);
          in.close();
      } catch (Exception e) { 
          fail("Failed to load properties: " + e.getMessage());
      }   // try
  }   // loadTestProperties
  </code></pre>
  
  <p>It always fails with null (properties were not loaded).  </p>
  
  <pre><code>&lt;project name="leads-testing" default="build" basedir="."&gt;
    &lt;property name="tst-dir" location="/Users/davea/Documents/workspace-sts-2.6.0.SR1/infinitiusa_leads_testing/test" /&gt;
    &lt;property name="db-props-file" location="/Users/davea/Documents/workspace-sts-2.6.0.SR1/infinitiusa_leads_testing/test/db.properties" /&gt;
    &lt;property name="TALK" value="true" /&gt;
  
    &lt;path id="classpath.base"&gt;
    &lt;/path&gt;
    &lt;path id="classpath.test"&gt;
      &lt;pathelement location="lib/junit-4.8.2.jar" /&gt;
      &lt;pathelement location="lib/selenium-java-client-driver.jar" /&gt;
      &lt;pathelement location="lib/classes12.jar" /&gt;
      &lt;pathelement location="${tst-dir}" /&gt;
      &lt;pathelement location="${db-props-file}" /&gt;
      &lt;path refid="classpath.base" /&gt;
    &lt;/path&gt;
  
    &lt;target name="compile-test"&gt;
      &lt;javac srcdir="${tst-dir}"
             verbose="${TALK}"
             &gt;
        &lt;classpath refid="classpath.test"/&gt;
      &lt;/javac&gt;
    &lt;/target&gt;
    &lt;target name="clean-compile-test"&gt;
      &lt;delete verbose="${TALK}"&gt;
        &lt;fileset dir="${tst-dir}" includes="**/*.class" /&gt;
      &lt;/delete&gt;
    &lt;/target&gt;
  
    &lt;target name="test" depends="compile-test"&gt;
      &lt;junit&gt;
        &lt;classpath refid="classpath.test" /&gt;
        &lt;formatter type="brief" usefile="false" /&gt;
        &lt;test name="com.criticalmass.infinitiusa.tests.InfinitiConfigOldG25Base" /&gt;
      &lt;/junit&gt;
    &lt;/target&gt;
  
    &lt;target name="all" depends="test" /&gt;
    &lt;target name="clean" depends="clean-compile-test" /&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Anyone know the correct way to load the properties file?  Thanks, - Dave</p>