title: Maven exec:java : how to open and read a file in the resources directory?
body: <p>here is the structure of my project.</p>
  
  <pre><code>proj
    ---src
      ----main
          ----java
              ----Main.java
          ----resources
               ----res.txt
  </code></pre>
  
  <p>I am using m2eclipse plugin with Eclipse. 
  In Main.java, I have</p>
  
  <pre><code>File f = new File("res.txt");  System.out.println(f.getAbsolutePath());
  </code></pre>
  
  <p>When I run mvn exec:java, the path got printed out is "...\proj\res.txt". How can I make it look for the resource file in "...\proj\target\classes" directory?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Thanks for the answers to my original question. I have a follow-up questions: </p>
  
  <p>So basically what I want to do is to have the Main class read the "res.txt" and then generate a new "newres.txt" to the resources directory so that I can package this new "newres.txt" to the jar file in the package phase later. Currently I mounted this exec:java to the prepare-package phase. How should I create this "newres.txt" in the resources directory without a hard-coded absolute path or depending on the directory structure of Maven?</p>