title: Apache Ant: adding and using a .txt file
body: <p>I'm using Apache Ant to compile, jar and run a java project for school. I've run into a problem that I don't know how to include a single .txt file into my .jar, and then reference it as well in my java code.</p>
  
  <p>Here is my compile and jar command in my build.xml. </p>
  
  <pre><code>    &lt;target name="compile"&gt;
          &lt;mkdir dir="build/classes"/&gt;
          &lt;javac srcdir="src" destdir="build/classes"/&gt;
      &lt;/target&gt;
      &lt;target name="jar"&gt;
          &lt;mkdir dir="build/jar"/&gt;
          &lt;jar destfile="build/jar/BinaryTree.jar" basedir="build/classes"&gt;
              &lt;manifest&gt;
                  &lt;attribute name="Main-Class" value="cs3345.MainLauncher"/&gt;
              &lt;/manifest&gt;
          &lt;/jar&gt;
      &lt;/target&gt;
  </code></pre>
  
  <p>What command do I use to include a .txt file into my jar. I've seen a couple Stack Overflow  questions about it already, notably</p>
  
  <p><a href="https://stackoverflow.com/questions/1216744/adding-non-code-resources-to-jar-file-using-ant">adding non-code resources to jar file using Ant</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2845228/how-can-i-include-data-text-files-in-a-jar-using-ant">How can I include data text files in a jar using Ant?</a></p>
  
  <p>But none of them really explained how to include a file. They just had commands that didn't really make sense to me. I've tried, </p>
  
  <pre><code>        &lt;jar destfile="build/jar/BinaryTree.jar" basedir="build/classes"&gt;
              &lt;manifest&gt;
                  &lt;attribute name="Main-Class" value="cs3345.MainLauncher"/&gt;
              &lt;/manifest&gt;
              &lt;fileset dir="src/resources" /&gt;
          &lt;/jar&gt;
  </code></pre>
  
  <p>But that didn't seem to help because I just don't understand Ant, I couldn't find documentation for it that actually explained why you do different things in ant.</p>
  
  <p>My .txt file is in, src/resources. </p>