title: How to load an external properties file from a maven java project
body: <p>I have a maven java project, with a properties file in the src/main/resources directory. I've packaged the jar without the properties file in the jar, so it can be deployed to different environments with different settings, but the unit tests are failing</p>
  
  <p>The project structure is </p>
  
  <pre><code>Properties Application Project
  |-- pom.xml
  `-- src
      |-- main
          |-- java
          |   `-- java classes
          |-- resources
          |   `-- myProps.properties
  `-- target
      |--properties-app.jar
         myProps.properties
  </code></pre>
  
  <p>The values are loaded in this file</p>
  
  <pre><code>public class MyProperties {
  
      private Properties myProperties;
  
      public MyProperties() {
  
          File file = new File("./myProps.properties");
          try {
  
              myProperties = new Properties();
              FileInputStream myPropertiesInputStream = new FileInputStream(file);
              myProperties.load(myPropertiesInputStream);
  
          } catch (IOException e) {
  
              e.printStackTrace();
  
          }        
  
      }
  
      public Properties getPropertyValue() {
          return myProperties.getProperty("value");
      }
  
  }
  </code></pre>
  
  <p>The unit test is as follows</p>
  
  <pre><code>import static org.junit.Assert.*;
  
  import org.junit.Before;
  import org.junit.Test;
  
  public class MyPropertiesTest {
  
      private MyProperties myProperties;
  
      @Before
      public void setup() {
  
          myProperties = new MyProperties();
  
      }
  
      @Test
      public void testMyProperties() {
  
          assertNotNull(myProperties.getPropertyValue());
  
      }
  
  }    
  </code></pre>
  
  <p>What should I use to load the properties file from the target directory so I can build it successfully from the command line?</p>