title: How to override the properties file value through command line arguments?
body: <p>I have a property file which is like this - </p>
  
  <pre><code>hostName=machineA.domain.host.com
  emailFrom=tester@host.com
  emailTo=world@host.com
  emailCc=hello@host.com
  </code></pre>
  
  <p>And now I am reading the above property file from my Java program as - </p>
  
  <pre><code>public class FileReaderTask {
      private static String hostName;
      private static String emailFrom;
      private static String emailTo;
      private static String emailCc;
  
      private static final String configFileName = "config.properties";
      private static final Properties prop = new Properties();
  
      public static void main(String[] args) {
          readConfig(arguments);
      }
  
      private static void readConfig(String[] args) throws FileNotFoundException, IOException {
          if (!TestUtils.isEmpty(args) &amp;&amp; args.length != 0) {
              prop.load(new FileInputStream(args[0]));
          } else {
              prop.load(FileReaderTask.class.getClassLoader().getResourceAsStream(configFileName));
          }
  
          hostName = prop.getProperty("hostName").trim();         
          emailFrom = prop.getProperty("emailFrom").trim();
          emailTo = prop.getProperty("emailTo").trim();
          emailCc = prop.getProperty("emailCc").trim();
      }
  }
  </code></pre>
  
  <p>Most of the time, I will be running my above program through command line as a runnable jar like this - </p>
  
  <pre><code>java -jar abc.jar config.properties
  </code></pre>
  
  <p><strong>My questions are -</strong> </p>
  
  <ul>
  <li>Is there any way we can override the above attributes in the property file through command line without touching the file if needed? Since I don't want to modify my config.properties file always whenever I need to change any attributes value? Is this possible to do?</li>
  </ul>
  
  <p>Something like this should override the hostName value in the file?</p>
  
  <pre><code>java -jar abc.jar config.properties hostName=machineB.domain.host.com
  </code></pre>
  
  <ul>
  <li>And also, is there any way to add <code>--help</code> while running the <code>abc.jar</code> that can tell us more about how to run the jar file and what does each property means and how to use them? I have seen <code>--help</code> while running most of the C++ executable or Unix stuff so not sure how we can do the same thing in Java?</li>
  </ul>
  
  <p>Do I need to use CommandLine parser for this in Java to achieve both of the things?</p>