Monday, August 8, 2011

Using GWT configuration properties

One of the commenters to the blog here bring me to the nice idea to use configuration properties to configure the linker instead of sub classing the linker. I found the idea very nice and decide to play around this feature. I did this example just to demonstrate what you can do to extend the linker, which I created in my previously articles to be able to use properties as well.

First thing you need to know is how to use actually GWT configuration properties. Here is a link which describes the multi value properties but also gives you the overview about how to declare your own property. I decide to have a new property called cache.manifest which will be used to define the static files needed to be cached, which normally are not affected by the linker and for which I used sub classing before. Here the steps you need to proceed, to define your own linker:

  • Inside your <module>.gwt.xml define the configuration property by adding the following:
<define-configuration-property name="cache.manifest"
-multi-valued="true" />

  • After this line you can now specify the values of the property. As you can see from the definition above I define the property as multi valued, which means the property can have more then one value. To add properties do the following:

<extend-configuration-property name="cache.manifest"
="/Gwt2go.html" />
<extend-configuration-property name="cache.manifest"
="/images/*" />
<extend-configuration-property name="cache.manifest"
="/css/*" />


  • Make sure that you extend the property after you defined, otherwise you will get warning message.

Now the most important part here how to use this property from the linker. The linker gives you the current LinkerContext which has a function getConfigurationProperties(). This function contains all defined properties. Knowing this you can do the following:

  • Create a new method which reads the new configuration property:

protected String[] getPropsExtraFiles(TreeLogger logger,
LinkerContext context) {

// get the configured external properties, if any
// try to list the configuration properties here
// this files should be static external files

if (context.getConfigurationProperties().isEmpty()) {
"Info: No external static options "
+ " have been configured, configuration-property cache.manifest "
+ " is empty!");

return new String[0];

else {

<ConfigurationProperty> it = context

while (it.hasNext()) {

ConfigurationProperty prop

if (prop.getName().equalsIgnoreCase(CONFIG_PROPERTY)) {

<String> props = prop.getValues();

return (String[]) props.toArray(new String[0]);



return new String[0];


  • now you can use the new function like this for example:

String[] cacheExtraFiles = getPropsExtraFiles(logger, context);

if (cacheExtraFiles.length == 0) {
= getCacheExtraFiles();

for (int i = 0; i < cacheExtraFiles.length; i++) {

This means if it’s property defined then use it, otherwise try to get the from the extended class.

You can find the full source code here and here! Also check the this and this, to see what was modified!


No comments:

Post a Comment