Debugging a servlet with tomcat and Eclipse tutorialFrom WikiJavabuy this book
It's always good to know what's going on under the hood. note: this tutorial doesn't explain how to do the actual debugging, for information about this see the how to debug tutorial
the articleThe process configuring the debugging a Java servlet may appear scaring and complex to the beginners, in this tutorial I will explain you how does it work and show you an example. ConceptsThe debugging of a web application involves several components:
As you may notice the connection between the application server and the IDE uses the TCP/IP protocol, this implies that you don't need to have the tomcat running on your same machine, you don't even need to be in the same continent of it. It is enough that you have network access (ex. internet) to the server, and you can debug whatever application wherever in the world. Isn't this the coolest thing ever? Setting tomcat in debug modeTomcat comes ready for debugging. To enable the debug mode you just need to write the following commands (under windows OS, analogous commands under different OSs): set JPDA_ADDRESS=8000 set JPDA_TRANSPORT=dt_socket catalina.bat jpda start ensure to execute this from the {catalina_home}/bin directory. For simplicity I normally generate a shell script (a .bat file) to automatize the process. I call this file debugmode.bat, it contains the three commands listed above and I normally put it in the {catalina_home}/bin directory. I am then able to start the tomcat in debug mode just by double clicking on this file with the mouse. Deploying your application to TomcatIn order to debug your application you must deploy it in the application server, you do this in the normal way. Nothing special about this. Connecting Eclipse to Tomcat for debuggingTo connect Eclipse to the debug server created by tomcat follow these simple steps:
at this point eclipse will connect to the debug server loaded in Tomcat, so it's important to do this procedure after you load Tomcat. You can set some breakpoints on your servlet and you will see that nothing happens. This is because the servlet is indeed NOT executed yet. Proceeding with the debugTo execute the servlet, and start debugging your code you simply open your web browser (for example firefox) and navigate to the address of your servlet, this will execute it. The execution will block at the point you put your breakpoint and the web browser will block too, waiting for the page. At this point you can normally debug your application as you do with other programs. Note that your IDE is running on your machine, while the servlet is running on the application server, and so is the debugger. The two latter elements are working on the same machine, but the machine for them may be different than your local one. Through the web browser you can call the servlet as many times as you want and your Eclipse will be showing you the details about these executions, without actually needing to click again on the debug button, this may be very handy. See Alsohow to debug tutorial, Deploying in Tomcat tutorial |




Thanks Buddy !
--125.16.95.12 17:56, 20 April 2009 (UTC)