Question

When using GWT to configuration usually go into your web.xml. It is normal to have different settings for development and production environment. I know that I can also use my static html host page to pass parameters to GWT.

What is a best practice to switch my configuration between development and production?

No correct solution

OTHER TIPS

Simply create multiple properties file one for each enviroment to store the environment specific settings.

Please have a look at below post to read the properties file at the time of server start-up.


EDIT

I want to write a property in my static html file which will be read by gwt. If the property is dev gwt should load test1.gwt.xml if property is prod gwt should load test2.gwt.xml.

Sample code that is written in your welcome file (index.jsp).

<!-- Read environment attribute from application -->
<% String evn = application.getAttribute("env"); %>

<% if("prod".equalsIgnoreCase(env)) { %>
    <script type="text/javascript"
             src="myproject/test2.nocache.js"></script>
<% } else { %>
    <script type="text/javascript"
             src="myproject/test1.nocache.js"></script>
<% } %>

Note: You can use JavaServer Pages Standard Tag Library instead of Scriptlets.

In my experience, configuration in a Java application is generally best managed via property files. I might suggest the following:

  1. Create a property file to store this flag, for example: remoteLogging=true

  2. Create a class on the server side that stores this type of configuration, for example SystemConfiguration with a Boolean property remoteLogging.

  3. At startup of the web application, inject the value of your properties into a singleton SystemConfiguration bean.

  4. On the client side, in your entry point (e.g. Application.java), in onModuleLoad() call the server to fetch the SystemConfiguration object.

  5. Keep the SystemConfiguration object in memory on the client side, and whenever you need, check - for example if(systemConfig.getRemoteLogging()) { LOG.info("foo"); }

Another path to go might be to have multiple versions of your .gwt.xml files (where remoteLogging log levels can be set), and have your build tool deploy the appropriate .gwt.xml file per environment. This would necessitate having building separately per environment though, which is generally not desirable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top