Created
October 15, 2014 21:15
-
-
Save lihonosov/279e48252a2061cbd119 to your computer and use it in GitHub Desktop.
Remote debug tomcat in eclipse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Starting Apache Tomcat in debug mode | |
| First of all we have to restart the Tomcat with debug option for this purpose we need to pass to JVM (Java Virtual Machine) the options | |
| -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n | |
| JVM opens a port in current machine allowing external applications (like Eclipse) to connect for debugging purposes. | |
| To do that with Tomcat we have to set the environment variable JAVA_OPTS that is read by Tomcat in startup.sh file. | |
| 1) Set variable and make it available. we can choose the port number, in this example is used 8000 number. | |
| export JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" | |
| 2) Start Tomcat (from bin folder): | |
| ./startup.sh | |
| Configuring Eclipse to remote debugging | |
| First of all, we have to open or import the project with the source code of the application we want to debug. Afterward we have to setup the debug from Eclipse: | |
| 1) Clicking on the right side (arrow facing to above) of the “Debug” button (the button with the bug) that is in the toolbar and the clicking on “Debug configurations…” or in the menu Run > Debug configurations… Then a new window with the different debug configuration will be opened. | |
| Debug configuration | |
| 2) Select “Remote Java Application” in the left menu and then press on “New launch configuration” button (the button with the folder icon in the top-left corner). | |
| New debug configuration | |
| 3) Fill the configuration with the data corresponding with our Tomcat instance: | |
| Project: The project we want to debug: it has to contain the source code for the application we want to debug. | |
| Connection Type: Standard (Socket Attach). | |
| Host: IP of the server in which is Tomcat installed. | |
| Port: Port indicated to JVM in address parameter. Port 8000 in our example | |
| Debug configuration sample data | |
| Remote Debugging of Tomcat with Eclipse | |
| 4) Execute the debug. We have to click on the button “Debug” and Eclipse will connect with Tomcat (it had to be previously running as I mentioned in this post). Now we have to put the breakpoints inside the Eclipse project to debug as we do with a regular project running in a local Tomcat. | |
| And that’s all, if everything works well you can debug your Tomcat remotely. Now there is a long work to do debugging your app. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment