title: Building a unified config.properties. What if there are multiple properties with the same key in a properties file in Java?
body: <p>We have a situation where there are a dozen of files called <code>config.properties</code> in our build process:</p>
  
  <ul>
  <li><code>config.properties.dev</code></li>
  <li><code>config.properties.qa</code></li>
  <li><code>config.properties.prod1</code></li>
  <li><code>config.properties.prod2</code></li>
  </ul>
  
  <p>Our current install process copies the <code>config.properties</code> for that environment to <code>config.properties</code>. (I'm not thrilled about this, but this is what I have to work with now.)</p>
  
  <p>All of these files are exactly the same except for three or four properties. Unfortunately, these aren't always the same property across all of the files. What we'd like to do is setup a <em>master</em> <code>config.properties</code> like this:</p>
  
  <h3>Master <code>config.properties</code></h3>
  
  <pre><code>prop1 = value1
  prop2 = value2
  prop3 = value3
  prop4 = value4
  </code></pre>
  
  <p>Then have a separate `config.properties for each environment that contains only the properties that differ from the master:</p>
  
  <h3><code>config.properties.prod</code>:</h3>
  
  <pre><code>prop3 = value3.1
  prop4 = value4.1
  </code></pre>
  
  <h3><code>config.properties.qa</code></h3>
  
  <pre><code>prop2 = value2.1
  prop3 = value3.2
  </code></pre>
  
  <p>We thought it might be possible to concatenate the two files together when we do a deployment:</p>
  
  <pre><code>cat config.properties.$env &gt;&gt; config.properties
  </code></pre>
  
  <p>And get a combined properties file this way:</p>
  
  <h3>Combined <code>config.properties</code></h3>
  
  <pre><code>prop1 = value1
  prop2 = value2
  prop3 = value3
  prop4 = value4
  prop2 = value2.1
  prop3 = value3.2
  </code></pre>
  
  <p>Unfortunately, we don't know how Java handles such a file. Does it take the first defined property, or the last defined property, or is the behavior completely undefined?</p>
  
  <p>If this won't work, what's the best way in a configuration script (which is usually a BASH script) to combine multiple properties into a single property file?</p>