Debugging a Google Webkit project with JDB
Tagged:  •    •    •  

I followed the tutorial of Google Web Toolkit and I must say it looks quite nice. Now I want to start a project with this toolkit, but I need a way to debug my code.

The tutorial suggests using Eclipse, but I refuse to use this monster on my poor old laptop. I thought it would be sufficient to use jdb for the time being. jdb is a command line debugger for Java applications. It's not as feature rich as gdb, but it will do.

To attach the debugger to your web application, you need to run it in hosted mode. The Ant build file should be modified in order to open a port which the debugger can attach to. Open up the build.xml file and add the following line:

  <target name="hosted" depends="javac" description="Run hosted mode">
    <title>
    ...
      <jvmarg value="-Xmx256M"/>
+       <jvmarg value="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"/>
      <arg value="-startupUrl"/>
    ...
    </title>
  </target>

Now start the hosted mode:

ant hosted

and your web project should be up and running.

You can connect on port 8000 to your web application:

jdb -attach 8000

You should be able to debug your application now throught jdb.