Saturday, October 1, 2016

Re: Using Constants based on Environment

Thanks for your response Jens.

For the maven configuration, I have a *.Dev.gwt.xml and a *.Prod.gwt.xml being referenced from the maven profiles. I'll see if I can directly filter resources there.


Since, I am using GWT 2.8, the second option you mentioned works great with my current setup.

As a follow up, is it possible to have the appropriate interface resource being picked from the *.gwt.xml instead.

For e.g., something like this wont work since here I only have interfaces as opposed to implementations below:

<replace-with
 
class="com.test.client.ClientFactoryImpl">
 
<when-type-is class="com.test.client.ClientFactory" />
</replace-with>


--Harsh

On Friday, September 30, 2016 at 6:20:58 PM UTC-4, Jens wrote:
Ideally your build tool should put your environment into prod or dev mode and the GWT app shouldn't know/care about it. With Maven / Gradle / Ant you can use "resource filtering" to rewrite resources like property files while being copied to the output folder. 

In that case you would have

Config.properties:
key = ${key}

dev.properties:
key = devValue

prod.properties:
key = prodValue

and the build tool will replace ${key} with the value of one of the other two files before GWT will pick up config.properties.


Otherwise you might try (no idea if it works):

interface Config extends Constants {...}
interface DevConfig extends Config {...} -> create a file DevConfig.properties
interface ProdConfig extends Config {...} -> create a file ProdConfig.properties

and in Java code

Config config;
if ("dev".equals(System.getProperty("env")) {
  config = GWT.create(DevConfig.class);
} else if ("prod".equals(......)) {
  .....
}

Can't remember, but System.getProperty() might require GWT 2.8.


-- J.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment