Debugging an application in an externally configured Tomcat

Thus far, we have debugged our application using Tomcat configured within Eclipse. When we launched Tomcat in Debug mode, Eclipse took care of adding the JVM parameters for debugging to the Tomcat launch script. In this section, we will see how to launch an external (to Eclipse) Tomcat instance and connect to it from Eclipse. Although we are going to debug a remote instance of Tomcat, information in this section can be used for connecting to any remotely running Java program that is launched in Debug mode. We have already seen the debug parameters to pass when launching a remote application in Debug mode.

Launching Tomcat externally in Debug mode is not too difficult. Tomcat startup scripts already have an option to start the server in Debug mode; you just need to pass the appropriate parameters. From the Command Prompt, select the <TOMCAT_HOME>/bin folder and type the following command in Windows:

>catalina.bat jpda start 

Launching Tomcat in Debug mode in Mac OSX and Linux:

$./catalina.sh jpda start  

Passing the jpda argument sets the default values to all the required debug parameters. The default debug port is 8000. If you want to change it, either modify catalin.bat/catalin.sh or set the environment variable JPDA_ADDRESS as follows:

Setting JPDA_ADDRESS environment variable in Windows:

>set JPDA_ADDRESS=9001  

Setting JPDA_ADDRESS environment variable in OSX and Linux:

$export JPDA_ADDRESS=9001  

Similarly, you can set JPDA_SUSPEND to y or n to control whether the debugger should wait for the client to connect before executing the main class.

To connect the debugger from Eclipse to a remote instance, select the Run | Debug Configurations... menu. Right-click on the Remote Java Application node in the list view on the left and select New:

Figure 6.14: Inspecting a variable

Set the appropriate Project and Port (the same as what you selected to start Tomcat in Debug mode, that is, the default: 8000) and click Debug. If the debugger connection is successful, Eclipse will switch to the debug perspective. From here on out, the process of debugging is the same as that explained earlier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.123.106