title: reading a file from a relative path in a maven project
body: <p>I have my java file in </p>
  
  <blockquote>
    <p><strong>/src/main/java/Test.java</strong></p>
  </blockquote>
  
  <p>and I want to read a property file/XML file from </p>
  
  <blockquote>
    <p><strong>/src/main/resources/plugin.properties</strong> and/or </p>
    
    <p><strong>/src/main/resources/templates/basic_java.xml</strong></p>
  </blockquote>
  
  <p>When I try to read these files from Test.java (after deployment of course), it is not able to do so and giving the error </p>
  
  <blockquote>
    <p>java.io.FileNotFoundException: /target/plugin.properties (No such file
    or directory)
            at java.io.FileInputStream.open0(Native Method)</p>
  </blockquote>
  
  <p>Though I can find the <strong>plugin.properties</strong> and <strong>basic_java.xml</strong> under <strong>/target/classes</strong> folder, yet it cannot read these files.</p>
  
  <p>I have tried multiple solutions including :</p>
  
  <pre><code>1. getClass().getResource("Test.java");
  2. new File(".").getCanonicalPath() + "target//plugin.properties";
  3. ((URLClassLoader) Thread.currentThread().getContextClassLoader()).getURLs()
  4. ((URLClassLoader) Thread.currentThread().getContextClassLoader()).getResourceAsStream("Test.java")
  5. Thread.currentThread().getContextClassLoader().getSystemResources("Test.java");
  6. new FileInputStream("src\\main\\resources\\plugin.properties");
  7. new FileInputStream("resources\\plugin.properties");
  8. new FileInputStream("src\\main\\resources\\plugin.properties");
  9. new FileInputStream("\\plugin.properties");
  10. new FileInputStream("\\classes\\plugin.properties");
  </code></pre>
  
  <p>but no luck.</p>