Showing posts with label debugger. Show all posts
Showing posts with label debugger. Show all posts

Tuesday, May 26, 2009

GWT with maven and eclipse

Setting up a latest GWT project in eclipse along with Maven was not straight forward. Here is step-by-step guide on how I managed to setup my environment.

I assume you have Eclipse installed with m2eclipse plugin. Also Maven installed and its maven executable is in your environment PATH.

Run the below maven archetype to create a project shell. I named my project gwttest.

mvn archetype:create -DarchetypeGroupId=com.totsp.gwt -DarchetypeArtifactId=maven-googlewebtoolkit2-archetype -DarchetypeVersion=1.0.4 -DgroupId=com.gwttest -DartifactId=gwttest

The above command will create a directory "gwttest".

In the generated pom.xml, change the gwt version to the version you are using. The version should be available in the maven repository. I used latest GWT version 1.6.4. Also remove the pluginRepositories and unpack plugin from the pom.xml as that it is not required.

Create an Application.launch file in your project with the below content. Launch file is required to run the project from Eclipse.

<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="gwttest" path="1" type="4"/> "/>
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="gwttest/src/main/java" path="3" type="2"/> "/>
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento project="gwttest"/> </runtimeClasspathEntry> "/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="gwttest"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.google.gwt.dev.HostedMode"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-war target\gwttest-1.0-SNAPSHOT com.gwttest.Application"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx256M"/>
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
</launchConfiguration>


In Eclipse go to File > Import > General > Maven Projects. Select the directory "gwttest" and finish.

To generate a war file right click on the project > Run As > Maven package. The war file will be created under gwttest\target folder.

To test right click on the Application.launch file > Run As > Application. The sample GWT application will start in hosted mode.

To debug right click on the Application.launch file > Debug As > Application.

Tuesday, May 5, 2009

Configure Eclipse for Remote Debugging

A J2EE developer always finds it difficult to debug a web application. The developer has to rely on log4j logging to understand what is happening. Although exception stack trace provides valuable info but at times it's not enough to debug a problem. Even for a trivial problem sometimes debugging takes ages. What if a developer can follow the execution in real-time and able to see the flow, values assigned to the variables, etc. Well a Java debugger is there to make debugging comfortable and quick. My favorite Eclipse IDE provides the remote debugging with lots of useful features.

But first we need to know how to enable a JVM to be debugged remotely. Any application server like JBoss, Tomcat, Weblogic, etc. or a simple JVM instance can be debugged remotely. Pass the following arguments to a JVM to enable remote debugging.

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

If both the debugger and target JVM is 5.0 and above then the preferred way is given below, although the above will also work.

-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n

More information of Java debugger is available here

To enable Jboss or Tomcat for remote debugging, you need to set JAVA_OPTS environment variable with the above arguments. Start the server, the Java Debugger is ready to listen on the defined port.

Follow the below steps to configure Eclipse for debugging -

  • In Eclipse go to Run > Debug Configurations..., a popup will open.

  • Right click on "Remote Java Application" and select New.

  • Give some name so that you can identify this debugger.

  • Select a project which you want to debug.

  • Select "Standard (Socket Attach)" as Connection Type.

  • Provide the host and port details where the remote JVM is running. For the above example port number will be 8787.

  • Click on Debug and Eclipse will open the Debug perspective which provides lots of helpful features.


  • The first task to debug a problem is to set breakpoints in the code where you think the problem persists. Eclipse allows conditional breakpoints which gets triggered when the defined condition evaluates to true. At runtime value of a variable can be changed to debug the code. Another useful functionality is to add a Java exception breakpoint, which gets triggered when the said exception is thrown.