It is always useful to debug the code in a line by line fashion to track where the code went wrong. Since I am using Apache Tomcat server for development purpose this article deals with enabling debugging on Apache Tomcat with Eclipe IDE.
First we need to set up the Tomcat server to enable debugging. Usually the debugging port used for tomcat is 8000, but you can set to any free port.
1. Open the startup.bat file from Tomcat directory (<Tomcat Installation Directory>/bin/)
2. After the script initializes the command line arguements, most probably towards end of file, add these two lines :
3. Change the line where it calls the EXECUTABLES to :
call “%EXECUTABLE%” jpda start %CMD_LINE_ARGS% (add jdpa start).
Save the file and start the tomcat. Now the first line of the tomcat startup console will show :
Listening for transport dt_socket at address: 8000
At this point your Tomcat server is ready to be run in debug mode. Now do the following steps at Eclipse IDE for debugging in Eclipse.
1. Open one class where you want to put breakpoint and add one breakpoint. (This can be done by clicking on the left margin on the corresponding line.
2. From Run menu, select Debug Configurations
3. From the left side, right click on Remote Java Application and click new
4. Fill out the form appearing. Only thing to take care is the server name should be localhost and port number 8000. This can be changed if you are debugging on a remote server.
5. Click on debug and now the eclipse is running in debug mode.
Now you can run the application and whenever the thread reaches the line, where you have put the breakpoint, it will pause execution. Then you can see the current values of the variables, you can step by step execute the line and so on.
That’s it guys. Happy Coding :)