Is there way to compile GWT in production mode?

807 views
Skip to first unread message

vikram dave

unread,
Nov 18, 2013, 9:41:57 PM11/18/13
to google-we...@googlegroups.com
Hi,

I am trying to compile my GWT code in production mode using Maven. I set production mode true (as seen below) in my pom, but I still see Dev mode code in my JS files. I don't want any dev mode code in my production JS file. Is there a way to do this using Maven? Can I set some flag/ property in my pom or *.gwt.xml file? 

            <!-- Compile Using GWT -->

            <plugin>

                <groupId>org.codehaus.mojo</groupId>

                <artifactId>gwt-maven-plugin</artifactId>

                <version>2.5.1</version>

                <executions>

                    <execution>

                        <goals>

                            <goal>compile</goal>

                        </goals>

                        <configuration>

                        <productionMode>true</productionMode>

                            <classifier>war</classifier>

                            <warSourceDirectory>src/main/webapp</warSourceDirectory>

                            <webappDirectory>war</webappDirectory>

                            <module>${Module Name}</module>

                            <extraJvmArgs>${gwt.extraJvmArgs}</extraJvmArgs>

                        </configuration>

                    </execution>

                </executions>

            </plugin>


I see that Ant lets you compile in production mode  by using following in build.xml file. Is there a way I can do this in maven? Or using Ant plugin in Maven? (If yes please share an example or point me to a good doc)

  <target name="gwtc" depends="javac" description="GWT compile to JavaScript (production mode)">

    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">

      <classpath>

        <pathelement location="src"/>

        <path refid="project.class.path"/>

        <pathelement location="../../validation-api-1.0.0.GA.jar" />

        <pathelement location="../../validation-api-1.0.0.GA-sources.jar" />

      </classpath>

      <!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->

      <jvmarg value="-Xmx256M"/>

      <arg line="-war"/>

      <arg value="war"/>

      <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->

      <arg line="${gwt.args}"/>

      <arg value="com.google.gwt.sample.hello.Hello"/>

    </java>

  </target>



Thomas Broyer

unread,
Nov 19, 2013, 5:49:34 AM11/19/13
to google-we...@googlegroups.com
What GWT calls "production mode" is running the JavaScript generated from the Java code by the GWT compiler, so the very fact of compiling from Java to JavaScript gives you "production mode"; there's no such thing as "compiling in production mode" and "compiling in some other mode" (there's "draftMode" but it's just one way to tweak the compilation process and its output, it's still "production mode").

The <productionMode> configuration in the gwt-maven-plugin applies to the gwt:test goal, not to gwt:compile.

The gwt:compile goal is exactly equivalent to the Ant snippet you gave: it launches the GWT Compiler to compile the Java code to JavaScript.

Note: the other modes are "dev mode" and "super dev mode": "dev mode" runs your code in Java (not JS), and "super dev mode" runs your code in "production mode" but in a way that makes it fast to (re)compile (i.e. not optimized) and using a resilient compiler, which makes it unsuitable for production (you don't just compile your code to JS, you also highjack code into your page with a bookmarklet so that you ask the super dev mode codeserver to recompile the code before serving it)

I thus don't understand what you mean by “I still see Dev mode code in my JS files”, what kind of code are you referring to?

Vikram Dave

unread,
Nov 21, 2013, 7:35:50 PM11/21/13
to google-we...@googlegroups.com
Thanks for the explanation, Thomas. The issue is, I have two GWT application (two separate projects compiled using GWT)  running on the same page. I am trying to debug an application, but the "isHostedMode" code in the other JS file, generates an alert. 
What I am trying to do is to get rid of "isHostedMode" method generated by GWT in my JS file (I wouldn't want alerts in my production file). 

function isHostedMode(){
    var result = false;
    try {
      var query = $wnd_0.location.search;
      return (query.indexOf('gwt.codesvr=') != -1 || (query.indexOf('gwt.hosted=') != -1 || $wnd_0.external && $wnd_0.external.gwtOnLoad)) && query.indexOf('gwt.hybrid') == -1;
    }
     catch (e) {
    }
    isHostedMode = function(){
      return result;
    }
    ;
    return result;
  }
if (isHostedMode()) {
    alert('Cross-site hosted mode not yet implemented. See issue ' + 'http://code.google.com/p/google-web-toolkit/issues/detail?id=2079');
    return;
  }

I changed the linker to use 'xsiframe' as suggested and the code change in the generated code are as follows.

function isHostedMode(){
    var query = $wnd_0.location.search;
    return query.indexOf('gwt.codesvr.Hello=') != -1 || query.indexOf('gwt.codesvr=') != -1;
  }

if (isHostedMode()) {
      return computeUrlForResource('Hello.devmode.js');
}

Is the any flag/property I can set so that above method doesn't get generated?

Thomas Broyer

unread,
Nov 22, 2013, 5:43:20 AM11/22/13
to google-we...@googlegroups.com
You don't need to compile your module differently depending on which one you want to in devmode or prod mode; this can be done at runtime; see https://code.google.com/p/google-web-toolkit/issues/detail?id=2079#c21
Reply all
Reply to author
Forward
0 new messages