title: Maven project doesn't put files in src/main/resources on classpath
body: <p>I have a java project in Eclipse. I want a read file that is in a certain folder. I use this code:</p>
  
  <pre><code>File file = new File("directory/filename.txt");
  </code></pre>
  
  <p>If I have a simple java project, with this layout:</p>
  
  <pre><code>Project
  |
  +- src
  +- lib
  +- directory
     |
     + filename.text
  </code></pre>
  
  <p>The code works fine and I can read the file. If I now convert this project to a maven project, Not much changes in Eclipse except a pom.xml file is made and a target folder is added (revaling the previously hidden "bin" output folder which is now a regular folder. The layout becomes:</p>
  
  <pre><code>Project
  |
  +- src
  +- lib
  +- bin
  +- target
  +- directory
  |  |
  |  + filename.text
  +- pom.xml
  </code></pre>
  
  <p>Because I want to use the maven project setup, I removed the src folder and added 4 new source folders to my project in Eclipse: </p>
  
  <p><a href="https://i.stack.imgur.com/lM63d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lM63d.png" alt="Source folders"></a></p>
  
  <p>I copied the <code>filename.text</code> to the resources folder, which should automaticcaly put its content on the classpath. My project layout becomes:</p>
  
  <pre><code>Project
  |
  +- src/main/java
  +- src/main/resources
  |   |
  |   + filename.text
  +- src/test/java
  +- src/test/resources
  +- lib
  +- bin
  +- target
  +- pom.xml
  </code></pre>
  
  <p>Now I noticed that this code doesn't work (NoSuchFileException)</p>
  
  <pre><code>File file = new File("filename.txt");
  </code></pre>
  
  <p>But this code does work:</p>
  
  <pre><code>File file = new File("src/main/resources/filename.txt");
  </code></pre>
  
  <p>Note: the way I run my code is by running it in eclipse as a java project. The file read code is a single line in my main method in my main class.</p>
  
  <p>I'm wondering what configuration I missed so that eclipse/maven regards the src/main/resources folder to be at the root of my classpath, rather than just a random folder that I have to explicitly name. It's especially weird, because another file in the resources folder, namely log4j.properties, is found and used by my log4j library without any problems. </p>
  
  <p>Note: If I build my project and install it in my local repository, I can actually see both files (filename.txt and log4j.properties) being neatly under target/classes.</p>