title: Setting log4j properties file via JVM argument - why does order matter?
body: <p>I have built a jar file which has a <code>log4j.properties</code> file in it (<code>mvn package</code> put it there by default from the <code>resources</code> directory). But when I run this jar file, I want to pass a different logging config, so I add <code>-Dlog4j.configuration=file:{path to file}</code>. The issue that bugs me is that the order matters here as follows:</p>
  
  <ul>
  <li>When I run <code>java -jar {path to jar} -Dlog4j.configuration=file:{path to file}</code> then it reads the log file packaged in the jar.</li>
  <li>When I run <code>java -Dlog4j.configuration=file:{path to file} -jar {path to jar}</code>, then it reads the config from the file I pass in the parameters.</li>
  </ul>
  
  <p>I have rough understanding how classpaths work in java and that if I were to load several java classes with the same name, it would make a difference. But this way I am passing a config parameter with a <code>-D</code> prefix, so the way I expect this to work is for some code in <code>log4j</code> library to check whether <code>-Dlog4j.configuration</code> is set and if so, then load the config from there, otherwise try to find it on the classpath.</p>
  
  <p>Any ideas on what I am missing?</p>