Welcome!

From the Trenches of the Enterprise Software

Yakov Fain

Subscribe to Yakov Fain: eMailAlertsEmail Alerts
Get Yakov Fain via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: Java EE Journal, Apache Web Server Journal, Eclipse Platform, Java Developer Magazine

J2EE Journal: Article

Debugging Both Flex and Tomcat Java Programs in Eclipse

Having the right debugging tools is crucial for any Web application

If you use Adobe Flex Web applications that connect to Plain Old Java Objects on the server side, chances are that you use a 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 the Java Platform Debugger Architecture (JPDA), which will allow other applications to attach to the 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 http://tomcat.apache.org/faq/development.html ).

Open the menu Program Files, Apache Tomcat 6.0 and start Apache Monitor Tomcat. In the right corner of the 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:

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

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 the 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 the 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, the Flex Builder debugger will pop up.

Note: If you see an error message, the chances are that you 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 the 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!

More Stories By Yakov Fain

Yakov Fain is a Java Champion and a co-founder of the IT consultancy Farata Systems and the product company SuranceBay. He wrote a thousand blogs (http://yakovfain.com) and several books about software development. Yakov authored and co-authored such books as "Angular 2 Development with TypeScript", "Java 24-Hour Trainer", and "Enterprise Web Development". His Twitter tag is @yfain

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Dario Laverde 11/12/07 03:30:22 PM EST

Hello Yakov,

Just want to point out that one doesn't have to always use JPDA when debugging Tomcat in Eclipse (or any IDE for that matter). You can define a run/debug configuration with org.apache.catalina.startup.Bootstrap as your main class running from Tomcat's home directory.

You can additionally avoid redeploying web apps (and restarting the debug session) by defining the docBase in the deployed context file to point to your application's workspace folder so as you edit files Tomcat automatically redeploys with each save.

regards,

Dario