title: What is best practice for setting java system properties, -D or System.setProperty()?
body: <p>I need to set the codebase for the RMI application I'm working on at the moment and have done this successfully using first </p>
  
  <pre><code>try{
    ResourceBundle config = ResourceBundle.getBundle("myApp");
    String codeBaseUrl = config.getString("codeBaseUrl");
    System.setProperty("java.rmi.server.codebase", codeBaseUrl);
  } catch (Exception e) {
    e.printStackTrace();
  }
  </code></pre>
  
  <p>and later using </p>
  
  <pre><code>java -Djava.rmi.server.codebase=http://192.168.1.1/path/to/codebase ...
  </code></pre>
  
  <p>on the command line.</p>
  
  <p>Both of these approaches allow for the codebase to be changed without the need to recompile, but the System.setProperty approach allows codebase to be bunlded into a properties file and the same launch command to be used.</p>
  
  <p>Most of the tutorials/documentation I've read on this uses the -D approach leading me to believe this is accepted as best practice, but I've been unable to find anything that explains WHY I should use over the other.</p>
  
  <p>Is -D considered best practice for setting system properties such as codebase, and what benefits does this give / what pitfalls does it avoid?</p>