title: Spring Boot: Is it possible to use external application.properties files in arbitrary directories with a fat jar?
body: <p>Is it possible to have multiple application.properties file? (<strong>EDIT</strong>: note that this question evolved to the one on the title.)</p>
  
  <p>I tried to have 2 files.</p>
  
  <ul>
  <li>The first one is on the root folder in the application Jar.</li>
  <li>The second one is on the directory which is specified in classpath.</li>
  </ul>
  
  <p>2 files are both named 'application.properties'.</p>
  
  <p>Is it possible to 'merge' the contents of both files? (and the second one's property values override the first one's) Or, if I have one file then the other file is ignored?</p>
  
  <p><strong>UPDATE 1</strong>: it is possible to 'merge' the contents. Yesterday it seemed that the first one was ignored, but it seems that it's because that something was broken then. Now it works well.</p>
  
  <p><strong>UPDATE 2</strong>: It's back again! Again only one of two files is being applied. It's strange... It started after I built the app jar file using Spring Tool Suite. And it seems that the Jar version always ignores the second one (in classpath), while the behavior of the expanded version which runs on STS varies. From where can I start to investigate?</p>
  
  <p><strong>UPDATE 3</strong>:</p>
  
  <p>The behavior of the Jar version was in fact correct. It's the specification of java.exe.
  When -jar option is specified, java.exe ignores both -classpath option and CLASSPATH environment variable, and the classpath will contain only the jar file. So, the second application.properties file on the classpath is ignored.</p>
  
  <p>Now, how can I let the second application.properties on the classpath be loaded?</p>
  
  <p><strong>UPDATE 4</strong>:</p>
  
  <p>I managed to load an application.properties file in external path while using -jar option.</p>
  
  <p>The key was PropertiesLauncher.</p>
  
  <p>To use PropertiesLauncher, pom.xml file must be changed like this:</p>
  
  <pre><code>&lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;  &lt;!-- added --&gt;
                  &lt;layout&gt;ZIP&lt;/layout&gt; &lt;!-- to use PropertiesLaunchar --&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>For this, I referenced the following StackOverflow question: <a href="https://stackoverflow.com/questions/21322673/spring-boot-properties-launcher-unable-to-use">spring boot properties launcher unable to use</a> . BTW, In Spring Boot Maven Plugin document(<a href="http://docs.spring.io/spring-boot/docs/1.1.7.RELEASE/maven-plugin/repackage-mojo.html" rel="noreferrer">http://docs.spring.io/spring-boot/docs/1.1.7.RELEASE/maven-plugin/repackage-mojo.html</a>), there is no mention that specifying ZIP triggers that PropertiesLauncher is used. (Perhaps in another document?)</p>
  
  <p>After the jar file had been built, I could see that the PropertiesLauncher is used by inspecting Main-Class property in META-INF/MENIFEST.MF in the jar.</p>
  
  <p>Now, I can run the jar as follows(in Windows):</p>
  
  <pre><code>java -Dloader.path=file:///C:/My/External/Dir,MyApp-0.0.1-SNAPSHOT.jar -jar MyApp-0.0.1-SNAPSHOT.jar
  </code></pre>
  
  <p>Note that the application jar file is included in loader.path.</p>
  
  <p>Now an application.properties file in C:\My\External\Dir\config is loaded.</p>
  
  <p>As a bonus, any file (for example, static html file) in that directory can also be accessed by the jar since it's in the loader path.</p>
  
  <p>As for the non-jar (expanded) version mentioned in UPDATE 2, maybe there was a classpath order problem.</p>
  
  <p>(BTW, I changed the question's title to be more specific to this issue.)</p>