title: Java load properties file correctly
body: <p>I have the following project structure:</p>
  
  <pre><code>ProjectName/src/java/com/main/Main.java
  </code></pre>
  
  <p>And I have a properties file in the following folder:</p>
  
  <pre><code>ProjectName/config/settings.properties
  </code></pre>
  
  <p>Now I tried to load the properties file in the Main.java with:</p>
  
  <pre><code>InputStream input = Main.class.getResourceAsStream("/config/settings.properties");
  Properties prop = System.getProperties();
  prop.load(input);
  </code></pre>
  
  <p>But this does not work. How is it the right way to do it?</p>
  
  <p>Edit: I got the following error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at java.util.Properties$LineReader.readLine(Unknown Source)
      at java.util.Properties.load0(Unknown Source)
      at java.util.Properties.load(Unknown Source)
  </code></pre>
  
  <p>Edit2: Now it works with eclipse. I did the following (adapted from <a href="https://stackoverflow.com/questions/18053059/getresourceasstream-is-returning-null-properties-file-is-not-loading">getResourceAsStream() is returning null. Properties file is not loading</a>)</p>
  
  <p>1) This directory [config] must be put into the "build path". Right-click the directory in the Package Explorer or Project Explorer view, select "Build Path", then "Use as Source Folder". Note: This build path will be the class path for the project, when you run it.</p>
  
  <p>2) As the config directory now is part of your class path and contains your properties file, you can simply load it with <code>InputStream input = Server.class.getClassLoader().getResourceAsStream("settings.properties");</code></p>
  
  <p>This works well for eclipse but not yet for a jar. I think I also have to add the build path somehow to the ant script.</p>
  
  <p>How can I do that?</p>
  
  <p>Edit3: If I take the settings.properties out of the config folder in the jar, then it works. Why? I want it in the config folder in the jar too. </p>