September 29, 2014

HOW-TO Use GWT SuperDevMode

GWT 2.5 introduced a concept of SuperDevMode which is a pretty awesome concept but I found it almost impossible to get it to work. The documentation just didn't explain enough of the missing pieces.
So before I get started, let me explain what it is/does. Recently a bunch of the browsers started to support the concept of source code maps. This feature has nothing to do with GWT and it just a way for someone to debug javascript that has been optimized/generated. These maps contains a mapping of the compiled source to the original source which then allows the debugged to display the original source.

So what GWT has done is provided a mechanism to integrate with this browser debugging feature to provide a way to debug through the compiled javascript BUT see the original java code. Awesome right!

The key thing I found extremely confusing is that you need to build and deploy the production version of your application. I use maven/tomcat to do this but you could use anything.
  1. Compile your application as normal (mvn clean install -DskipTests)
  2. Install the war into your local tomcat and start tomcat
  3. Execute java program at the bottom which will start the Code Server
  4. Go to http://localhost:9876/ and copy the bookmarks to you bookmark directory
  5. Go to the location version of the app (http://localhost:8080/yourwar/
  6. Click the "Dev Mode On" bookmark

You should now see the a SDM dialog come up and ask you to compile the app.  Once it is done compiling the app, you now are running a newly compiled version of the app within the browsers debugger. So you're not going to use the IDEs debugger anymore. Now you'll can open Chromes debugger and you should see the JAVA source instead of the javascript sources. You should be able to set a breakpoint.

While this is an awesome feature, I've found that using the standard mode still more useful for day-to-day debugging.  I do run into cases where its been essential. Recently, I had a race condition which never showed up in the standard debugger because it always executed so slowly.

  
https://www.youtube.com/watch?v=WqiZLM32kXY


public class SuperDevMode {

 public static final void main(String[] args) throws Exception {
  new File("target/gwt.tmp").mkdirs();
  CodeServer.main( new String[] {
    "-workDir" , "target/gwt.tmp",
    "-src","../gwt-utils/src/main/java",
    "-src","src/main/java",
    "com.gwt.module"
  });
 }
}

No comments: