load config file (project.properties) at runtime via command prompt in java

deepaksharma picture deepaksharma · Apr 3, 2014 · Viewed 15.9k times · Source

I would like to load properties file via command prompt in java.

Properties file name: project.properties

java -classpath .;test.jar; com.project.Main

What 'll be the command if I'll load the properties files via command prompt.

Thank in advance.

I have executed the below mentioned command on command prompt but not get any output.

java -classpath .;test.jar; -DPROP_FILE="C:\Program Files\DemoApp\config\project.properties" com.project.Main

Answer

sprabhakaran picture sprabhakaran · Apr 3, 2014

Send file path as below format,

java -classpath .;test.jar; -DPROP_FILE=conf\project.properties com.project.Main

Use below code for getting property file

String propFile = System.getProperty("PROP_FILE");
Properties props = new Properties();
props.load(new FileInputStream(propFile));

Thanks.