I spent some time trying to load the properties file and couldn't find any solution that worked. Here is a picture of my setup.
Properties file location: /sandbox/resources/properties/MessageBundle_en_US.properties
App location: /sandbox/src/main/java/com/app/sandbox/App.java
Not sure what is going on. I tried several combinations, but it just can't get past the exception. I even tried entire path of the folder. Can anyone tell me how ResourceBundle.getBundle() method looks for properties files?
UPDATE 1: This solution stopped working a few minutes later:
ResourceBundle mybundle = ResourceBundle.getBundle("MessageBundle");
UPDATE 2: The solution above no longer worked during my last run. So I changed it to:
ResourceBundle mybundle = ResourceBundle.getBundle("properties/MessageBundle");
And it worked. It seems there might be a caching issue with how ResourceBundle looks for the properties file.
I am still not sure how ResourceBundle class looks for the properties file. It says to pass a "baseName" parameter:
baseName - the base name of the resource bundle, a fully qualified class name
https://docs.oracle.com/javase/7/docs/api/java/util/ResourceBundle.html#getBundle(java.lang.String)
But it's not clear how it starts looking for the files. Does it start looking from the root of the project directory? If someone can answer this, it would be good. What does it mean by a fully qualified class name. I wouldn't think "properties.MessageBundle" is fully qualified.
Try using as below;
ResourceBundle bundle = ResourceBundle.getBundle("properties/MessageBundle");