Jobin Kuruvilla wrote a neat little blogpost "Reading from property file in v2 plugins" for JIRA plugins. This got me thinking that while people have asked, no one had written up how to do the same for Atlassian Confluence.
It's relatively straightforward, but while Jobin shows you how to read the properties file from WEB-INF/classes/ as well as the home directory, I'd recommend storing only storing properties files within the home directory, purely for ease of upgrade.
Anyway, here's the code:
// get the Confluence home directory
String applicationHome = BootstrapUtils.getBootstrapManager().getApplicationHome();
File file = new File(applicationHome, "some-file.properties");
FileInputStream fileInputStream = new FileInputStream(file);
Properties p = new Properties();
// read individual key
To test this out, you'll need to add your some-file.properties to the Confluence home directory. In your development environment, that's likely to be here:
If you're concerned about caching this (and you should be), call this code from an add-on initialisation method. To reload or update the properties, disable and re-enable the add-on. Or build a UI to trigger an update.