Apache Commons Configuration
でライブラリを使用していPropertiesConfiguration
ます。私のアプリケーションは、次のように、開始直後に構成ファイルをロードします。
public PropertiesConfiguration loadConfigFile(File configFile) throws ConfigurationNotFoundException {
try {
if (configFile != null && configFile.exists()) {
config.load(configFile);
config.setListDelimiter(';');
config.setAutoSave(true);
config.setReloadingStrategy(new FileChangedReloadingStrategy());
setConfigLoaded(true);
}
else {
throw new ConfigurationNotFoundException("Configuration file not found.");
}
} catch (ConfigurationException e) {
logger.warn(e.getMessage());
setDefaultConfigValues(config);
config.setFile(configFile);
}
return config;
}
私の質問は、どうすれば を検証configFile
できるので、そのファイルのプロパティが欠落していないことを確認でき、後でコードでNullPointerException
プロパティにアクセスしようとして も取得できません。
PropertiesConfiguration config = loadConfig(configFile);
String rootDir = config.getString("paths.download"); // I want to be sure that this property exists right at the app start
ドキュメントやグーグルには何も見つかりませんでした。XML検証に関するものだけです。
目標は、プログラムの開始時に構成ファイルが破損していることをユーザーにフィードバックすることです。
プロパティファイルの組み込みメカニズムはありませんか?