Tushar Digambar Deshpande Tushar Digambar Deshpande - 4 months ago 44
Java Question

Loading values from properties file dynamically in GWT

I am working on maven based GWT/MVP4G project. I have one property file and its corresponding interface at client side, both are named as

MyConstants.properties
and
MyConstants.java
and both are placed in a client folder. Interface is extended from
Constants
class of i18n library. I am taking required values from that property file by making its instance using
GWT.create(MyConstants.class)
. Whenever I compile and run the code it is working fine, giving me the required output.

But my main issue is, after creation of
war
of that project, if I edited that property file
MyContstants.properties
by extracting
war
and changed some content in it, then unable to access those newly edited changes.

Because I have to make those changes in project's
MyConstants.properties
file, then after recompilation and again creating new
war
then only I can access the edited changes. Is there any way to bind values dynamically to that property file, means is there any way without recompiling project can I reflect those war changes?

Please help me to get out of this problem, working on it, but unable to get the solution.

Answer

The values of the MyConstants.properties are inserted into the JavaScript-code during the GWT compilation. After the application is compiled, the property files can be removed.

That's why changing the property file after compilation has no effect.

.properties files are just intermediary files used in the compilation process.

If you want to change the values of the property file, you have to choose another way to do so.

Store your property-files on the server, create a call from your GWT application to the server, read the property file and return the values to the client.

In this case, the changes on the property file will be possible without recompiling your application.