Take the 2-minute tour ×

I'm attempting to use capabilities provided by maven profiles to build customized builds for different server environments. What I'm attempting to do is combine maven resource filtering


with it's profile mechanism


to convert this value in a file named server.cfg


to something I can use here:

public interface ServerResource extends ClientBundle {
    public static final ServerResource INSTANCE =  GWT.create(ServerResource.class);

    public TextResource server();


I can see that the value's been replaced in WEB-INF/classes but it doesn't appear that GWT used the file with the replacement to create the application javascript. How can I do this?

share|improve this question
It looks to me as you are hardcompiling in specific server properties in your GWT application. Is there are reason you don't get those values from the server via for example an Async callback when your application starts? This way you don't need to compile multiple versions in the first place. –  Hilbrand Bouwkamp Mar 6 '12 at 18:31
I'm a little new to this, so if I download my GWT app from my_server/instance1, how would callback know to go to my_server/instance1_services. This is ultimately what I want to do - and then have another application instance at my_server/instance2 and myserver/instance2_services. I tried to use ExternalSourceResource, but had no success with that. I've also looked into GIN, and couldn't figure that out either. –  Vinnie Mar 6 '12 at 23:28
Can you be more specific about what you exactly mean with services? Is it a separate deployed application? Are they actual webservice or GWT RPC servlets? How do you communicate with those services? –  Hilbrand Bouwkamp Mar 8 '12 at 18:18
Yes, it is a separate deployed RESTful web service application. I communicate with them over HTTP (and HTTPS). –  Vinnie Mar 8 '12 at 22:14
add comment

2 Answers

Using GWT compiler permutations to apply this kind of configuration is in my opinion a very bad idea. One of the most common complaints about GWT is the time it takes to compile, and by doing this you're just adding to the problem.

Configuration should usually be read from configuration files (surprise!), like shown here.

Anyway, what you're trying to do seems to me impossible. You cannot tell the client-side code to which server it should connect. This would violate the same-origin policy! The app can only communicate with the server it came from.

To have different apps running in different URLs, you would need to deploy several GWT apps with different names (even if they are basically the same). Then, you would just have to type the correct URL for each app (version) in the browser, and it will "look" at the right app. So you could have URLs like this:


In order to make a request to a different app running in the same server as the GWT application, you can do something like this:

String serviceUrl = "/app2/someService"; // or some other String sourced from a config file, using a GWT ClientResource for example
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,
    try {
        // send request from app1 to app2
        rb.sendRequest(null, new RequestCallback() {
            public void onResponseReceived(Request request,
                    Response response) {
                log.info("Response: " + response.getStatusText());
                // if response is 200 it's ok, you can read the outputStream to see what's in there
            public void onError(Request request, Throwable exception) {
                log.warning("Request Error", exception);
                // do something more
    } catch (RequestException e) {
        log.warning("Request Exception", e);
        // getting here means trouble with the connection or service!
share|improve this answer
It doesn't violate the same origin policy since it's going to the same server, just a different instance on the server - and I need to specify which instance it is. Flex has similar SOP restrictions, and we're attempting to replace our Flex UI with GWT. What you've suggested later in your post about different app versions is what I'm attempting to do - it's just that app1 uses app1_web_services and app2 uses app2_web_services. I need to specify that mapping someplace. In Flex I did it in the war packaging. I'll look at your configuration example. Thanks! –  Vinnie Mar 7 '12 at 13:59
The configuration file example you reference looks like it sets the configuration for server-side components. Is that true? What I want to do is set this type of configuration on client side components (visible to the js generated by the gwt compiler). –  Vinnie Mar 7 '12 at 21:17
BTW - I'd happily trade slow compile time performance for fast(er) run time performance. –  Vinnie Mar 7 '12 at 21:19
From what you wrote, it appeared to me you wanted to set the URL of the server you want to connect to. This would be impossible.You're mixing things up... when you use GWT.create(...), you're using deferred-binding (code.google.com/webtoolkit/doc/latest/…;. This does not have anything to do with maven profiles. I use Maven profile to build a "dev" or "prod" environment ("dev" basically only compiles to one browser, so it's must quicker). –  Renato Mar 7 '12 at 22:08
Please be more explicit about what you are trying to achieve, I think I might be able to help as I have played with deferred binding, Maven profiles and even GWT generators (which can do amazing things for you). I'm sure one of these solutions will do what you want (except connect to different servers). –  Renato Mar 7 '12 at 22:13
show 6 more comments
up vote 1 down vote accepted

I solved what I was trying to accomplish without the use of maven profiles or the GWT ClientBundle (which I never did get to work in the way I had intended when I wrote the question).

Here were the main issues I hoped to solve using maven profiles and the workaround I employed to solve the issue at hand:

  1. Use Mock MVP Models in Hosted Mode

    // inside the initialization for my model locator
    boolean hostedMode = GWT.getPermutationStrongName().equals("HostedMode");
    if (hostedMode) {
       // instantiate mock models
    } else {
       // instantiate real models to call REST web services
  2. Provide real models with correct RESTful server URL

    I was able to accomplish this because my GWT app and the RESTful web service url follow a set naming convention. I basically strip the trailing '/' from the URL and append '_services"

    String createServicesBaseUrl() {
        StringBuffer baseUrl = new StringBuffer(GWT.getHostPageBaseURL());
        int length = baseUrl.length();
        baseUrl.replace(length-1, length, "_services");
        return baseUrl.toString();
  3. Enable testing of as much of the MVP Presenter (Activities & Places) as I could

    I was already injecting the model locator into my Activity classes, so replacing that with a mock model locator for use by JUnit was straightforward. I did the same for my views and abstracted away some of the other code which didn't seem to work outside of the browser (like the GWT PlaceController).

All in all my build is much the same, but I learned how to gain a lot of flexibility in testing, configuring the server instance my GWT application connects with, and which model my application uses (dependent on hosted vs server mode).

share|improve this answer
Now I see what you were trying to do... interesting. –  Renato Mar 10 '12 at 4:03
add comment

Your Answer


