How to debug the code of a custom unit inside the Web application

by Laura Cigardi
8,447 views Published on Oct 24, 2011
Applies to: All versions
Table of contents


Thanks to the WebRatio integration in the Eclipse environment, now it's possible to easily debug a Web application without leaving the tool.

Usually, debugging a WebRatio generated web application means testing the custom units that have been developed for your specific Web project. The Eclipse Debug perspective can be used to test the unit service classes in order to check if the custom units behave correctly or not. Let's see how to configure the debug of a units project.

Debug configuration

First of all, you have to add breakpoints in the unit service. A breakpoint will stop the code execution at the specific instruction on which it is placed. You can add different breakpoints to different unit service classes of the same units project. Usually, a breakpoint is placed where you think the unit can behave in an undesiderable way.

You can also add conditions to a breakpoint. Conditions means that the breakpoint is considered only when the condition is sutisfied. For example, if you have different instances of the same custom unit in your Web project but you want to debug only a specific instance of that custom unit, given its id, you can specify a condition saying that only when the unitID variable is equal to that specific id the brakpoint will be active.

Once the breakpoints are set, you have to add a new debug configuration. Select the Debug... button from the main toolbar. In the opening dialog right click on Remote Java Application and choose the New command from the contextual menu. Enter a name for the new configuration and choose the units project containing the units you want to debug. Choose "Standard" for the Connection Type. In the Connection Properties type "localhost" for the host and type 8088 for the port number.

Now you have to configure your application server in order to run in debug mode. Let's see how to configure a Resin and a Tomcat server.

  • Resin application server. Create a new file with the .bat extension containing this line of code

   httpd.exe -java_home C:ProgrammiJavajdk1.6.0 -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8088

where -java_home is the directory in which you installed the java JDK

  • Tomcat application server. Open the catalina.bat file placed in the bin folder and add the following code

   set CATALINA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8088

In order to start debugging the Web application you have to

  1. start the application server in debug mode
  2. start the debug configuration from WebRatio

After that, you can freely navigate in the application and the code will automatically stop at the first enabled breakpoint. When the code stops at a specific line of code, if you are in the Eclipse Debug Perspective, you can do the following things:

  • you can check the values of many variables, just selecting them from the global list
  • you can go over the highlighted statement, pressing F6 (step over command). Execution will continue at the next line either in the same method or (if you are at the end of a method) it will continue in the method from which the current method was called. The cursor jumps to the declaration of the method and selects this line.
  • you can go into the highlighted statement, pressing F5 (step into command)
  • you can go out of the current method and jump to the next enabled brekpoint, pressing F8 (step return command). This option stops execution after exiting the current method.

In this way you can easily debug your java code and understand if the unit is behaving correctly or not. Remember that, every time you change the code of the unit service, you have to generate the Web project in order to have the debug configuration and the web application synchronized, otherwise what you see in the debug perspective is not the real source code of the unit service.


Related Learning Objects