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
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.
Run java -classpath .;test.jar; com.project.Main project.properties
, than read this argument in your main method and load the file.
public static void main(String[] args) {
String fileName = args[0];
Properties prop = new Properties();
InputStream in = getClass().getResourceAsStream(fileName);
prop.load(in);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With