public static void loadFilters() throws MalformedURLException {
File filtersFile = new File(CONFIG_DIR + "/" + FILTERS_FILE);
URL[] urls = {filtersFile.toURI().toURL()};
ClassLoader loader = new URLClassLoader(urls);
ResourceBundle bundle = ResourceBundle.getBundle(FILTERS_BASE, Locale.getDefault(), loader);
if (StringUtils.isNotBlank(getStringValue(bundle, ALLOW_TYPE_PATTERN_KEY))) {
ALLOWED_TYPES = Pattern.compile(getStringValue(bundle, ALLOW_TYPE_PATTERN_KEY));
}
if (StringUtils.isNotBlank(getStringValue(bundle, DENY_TYPE_PATTERN_KEY))) {
DENIED_TYPES = Pattern.compile(getStringValue(bundle, DENY_TYPE_PATTERN_KEY));
}
ALLOWED_MIME_TYPES = getListValue(bundle, ALLOW_MIME_PATTERN_KEY);
DENIED_MIME_TYPES = getListValue(bundle, DENY_MIME_PATTERN_KEY);
}
I am trying to load properties file using resource bundle kept outside the code in a separate directory. But when I try to do this way(above code) I am getting error as
ERROR [main] Can't find bundle for base name filters, locale en_US
And If I am keeping this file filters.properties in src/main/resources folder then this code is working fine… but when I keep it outside it doesn’t works.. Don’t know why..
And CONFIG_DIR contains \my\dir\conf and FILTERS_FILE contains filters.properties file.
FILTERS_FILE has value filters.properties and FILTERS_BASE has value filters and urls got the value as [file:/C:/my/dir/conf/filters.properties]
And filters.properties file is in /my/dir/conf/filters.properties
Try having the file point to the directory rather than the actual properties file. So just change the first statement of that method to
If
FILTERS_BASEcontainsfilters, that should be enough. You don’t need the fullfilters.propertiesname since the .properties prefix is appended by thegetBundlemethod.