1

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?

Michael
  • 32,527
  • 49
  • 210
  • 370

2 Answers2

1

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.

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
  • This answer has nothing to do with my question. I want to switch configurations not do remote logging. – Michael Mar 04 '14 at 13:49
  • What configuration are you talking about? Is it stored some where in properties file? What configuration does in the application? – Braj Mar 04 '14 at 13:51
  • 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. – Michael Mar 04 '14 at 14:27
  • I have updated my answer as per your requirement. Let me know if still there is any change is required. – Braj Mar 04 '14 at 14:43
  • How do I check the the property from within the gwt.xml file? – Michael Mar 04 '14 at 18:49
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/48988/discussion-between-braj-and-confile) – Braj Mar 04 '14 at 18:59
0

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.

throp
  • 696
  • 7
  • 10
  • How do I check the the property from within the gwt.xml file? – Michael Mar 04 '14 at 17:42
  • You can't. If your .gwt.xml file needs to have configuration that's environment dependent (e.g. PROD, TEST, etc.) then I believe you'll need to have multiple versions of these .gwt.xml files for each environment, and do a separate build per environment. – throp Mar 04 '14 at 19:38