Pregunta

So I have a GWT project and on the server side I am trying to load a properties file into a resource bundle, but am failing. I keep getting a missing resource exception because it can't locate the file but every option I've tried doesn't work. I've tried placing the config.properties file in war/config/config.properties as well as src/config/config.properties (so 2 copies) and I've tried calling it the following ways

TestGWTProject.war.config.config.properties
TestGWTProject.war.config.config
TestGWTProject.src.config.config.properties
TestGWTProject.war.config.config
src.config.config.properties
src.config.config

and my current call is this

ResourceBundle bundle = ResourceBundle.getBundle("config");

yet nothing works. Ideally, I'd like to keep it in the war file, but if it has to stay in src no biggie, but I'd like to just be able to find it at this point. What am i overlooking?

¿Fue útil?

Solución

If you put your properties in the src folder (as I think you should) you need to give ResourceBundle a class-like qualified name, so that when application gets compiled, it can find the properties file in the classes folder.

In my case, for ex., I place them in my source folder, inside a package. Like this:

src/package/subpackage/subsubpackage/propertiesFile.properties

When I want to load the properties, I use this as the qualified name:

package.subpackage.subsubpackage.propertiesFile

This is the same way you would give your application a full qualified name for a class. The key here is that the properties file is getting copied to the classes folder inside the WAR. So your mistake was telling the ResourceBundle to look into the src folder.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top