Igor
Igor

Reputation: 658

how to set custom system variable for JVM to access properties file?

I need to read config.properties file from location that i set with variable -Dapp.conf=/path/to/config.properties and set it to a Datasource when i launch my application. file should be at any location within filesystem. how to do this?

Upvotes: 1

Views: 1338

Answers (1)

Nicolas Filotto
Nicolas Filotto

Reputation: 45005

You can load your properties file as next:

Properties p = new Properties();
try (Reader reader = new FileReader(System.getProperty("app.conf"))) {
    p.load(reader);
}

Once loaded you can use your properties instance to set your datasource configuration.

Upvotes: 2

Related Questions