rodabi
rodabi

Reputation: 33

Parameterizing Java properties file at application launch

The application I have inherited is configured by a properties file passed in with a -D option from a shell script:

*-Dcom.gtnet.systemProperties.override.url=file:/usr1/app/gtx/config/override.properties_$INST*

We run multiple concurrent instances of this application, and currently each has an individual properties file. The only difference in each of the files is the name of the log file. So we end up with multiple, almost identical files spread across many servers.

My question, is there any way to parameterize, or extend the properties file in such a way that we could just pass in the name of the instance and use that inside the file? Thus we'd only have one file per server. We don't have the option of modifying the application code and we need to pass the file in at application start up.

Upvotes: 3

Views: 305

Answers (2)

ykaganovich
ykaganovich

Reputation: 14964

Java doesn't have support for this. If you really cannot change the app, you can wrap it with a launcher that will read in a parametrized properties file, resolve the parameters, and write out a temporary properties file with the parameters resolved; then invoke your app with that temporary file.

Upvotes: 1

Dilum Ranatunga
Dilum Ranatunga

Reputation: 13374

The built in java.util.Properties#load(...) supports neither #includes nor variable substitution.

If you happen to know the the application is not using Properties.load, but is instead its own logic, you can look into whether is does this... but barring existing support, you would have to modify the application code.

Since you mention that modifying the application code is not an option... you should consider using a properties file generator, and manage the template for generating the properties file. So you'd still have a bunch of fully expanded properties files, but they would be mastered using one template file, possibly a parameter values files, and the properties file generator.

Upvotes: 1

Related Questions