Debugging both Flex and Tomcat Java programs in Eclipse

If you use Adobe Flex Web applications that connect to Plain Old Java Objects on the server side, the chances are that you use popular, robust, and freely available server called Apache Tomcat. If you use Eclipse-based Flex Builder, you can smoothly debug both Flex and Java code without leaving Eclipse. Flex Builder debugger does not need any special configuration. But we need to add a couple of parameters to the startup routine of Tomcat so it‘ll engage Java Platform Debugger Architecture (JPDA), which will allow other application attach to JVM that runs Tomcat and debug deployed Java classes remotely.

You just need to add a couple of options to the JVM that starts Tomcat. In this short article I’ll explain how to do this if you install Tomcat using Windows Service Installer and run Apache Tomcat as a service under Microsoft Windows. But even if you start Tomcat using command files, JVM parameters remain pretty much the same (see ).

Open the menu Program Files, Apache Tomcat 6.0 and start Apache Monitor Tomcat. In the right corner of Windows toolbar, you’ll see a small icon with a little red square. Open it up, select the Java tab and add the following two options lines in the Java Options field:


This screen may look as shown below:

Press OK – your Tomcat will allow other clients to connect and get debug information through the port 8000. Now go to Eclipse and open Java perspective that contains the source code of the Java program that is deployed under Tomcat and needs to be debugged.

The next step is to configure parameters of the remote debug session. Select the Java program and then click on the menu Run | Debug, and then right-click on the option Remote Java Application on the left side of the window shown below. Select New from the menu and fill out the rest of the fields in this Window.

Note. The connection properties of Eclipse debug session should be configured to connect to the same port 8000, where Tomcat is publishing its debug information.

Close the debug configuration window, highlight the name of your Java class and press the button Debug, and it’ll start the debug session on this port. You can also start this debug session by right-clicking on your Java program name and pressing the button Debug.

The rest is simple – set a breakpoint in your Java program, and when this code will be executed, Eclipse brings the Java debugger and stops there. If you hit a breakpoint set in your ActionScript code, Flex Builder debugger will pop up.

Note. If you see an error message, the chances are that you’ve are trying to start the debug session on port 8000 more than once, which is not allowed.

This is not the only way to debug your Java code deployed under J2EE application server. For more debug options see Chapter 12 of the book Rich Internet Applications with Adobe Flex and Java.
Happy coding and debugging with Flex and Java!

Yakov Fain