For Eclipse or MyEclipse debug J2SE project or small application for breakpoint debugging, everyone is not unfamiliar, as long as the breakpoint set, debug run OK. But if it is a Web project, and the project is running in the container, such as Tomcat,resin, and so on, some students do not know how to debug breakpoints, can only take this method, is the use of System.out.println () printing method, which is not good, and waste a lot of time. The following summarizes the methods for debugging Web projects under MyEclipse under breakpoints.
Get ready
Environment: windxp,jdk1.6,myeclipse10.7,tomcat6.0.37
MyEclipse build the Web project Servlettest, and then create a testservelet.java that is not modified by the auto-generated code because it is used for testing.
Set a breakpoint on Testservlet.java
Look at the web.
[HTML] view plain copy
- <? XML version= "1.0" encoding="UTF-8"?>
- <Web-app version="3.0"
- xmlns="Http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
- Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd ">
- <display-name></display-name>
- <servlet>
- <description>this is the description of my EE component</description>
- <display-name>this is the display name of my EE component</display-name>
- <servlet-name>testservlet</servlet-name>
- <servlet-class>com.fei.servlet.testservlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>testservlet</servlet-name>
- <url-pattern>/servlet/testservlet</url-pattern>
- </servlet-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </Web-app>
All right, get ready for work.
Local debugging
Local debugging is the tomcat that is set to start in MyEclipse and has been started in debug mode. This is simple and does not require additional work.
1. Set up Tomcat
Window->preferences->myeclipse->servers->tomcat
Setting the startup mode
Deployment Project
Start the service
Browser input Address: Http://localhost:8080/servlettest/servlet/TestServlet
MyEclipse switch to debug view, here everyone is not unfamiliar.
Remote debugging
Remote debugging, is relative to MyEclipse, is that Tomcat is not started in MyEclipse, but to start the external itself, or tomcat running on another server, not and myeclipse the same computer. In the above local debugging, the most important thing is that Tomcat boot mode is set to debug mode, so for remote debugging, Tomcat must be in debug mode to boot, and then MyEclipse and Tomcat to set up the connection.
Open the Tomcat bin directory and find Catalina.bat and Startup.bat copy, named Catalina_debug.bat,startup_debug.bat.
Open Startup_debug.bat and precede the phrase "current_dir=%cd%" with the following:
Set jpda_address=8000
Set Jpda_transport=dt_socket
Set Catalina_opts=-server-xdebug-xnoagent-djava.compiler=none-xrunjdwp:transport=dt_socket,server=y,suspend=n, address=8000
The above debug listening port 8000 can be replaced with unused ports
:
At the same time, the Catalina.bat in the text is replaced with Catalina_debug.bat.
Open the Catalina_debug.bat, and precede the set "current_dir=%cd%" with
SET Catalina_opts=-server-xdebug-xnoagent-djava.compiler=none-xrunjdwp:transport=dt_socket,server=y,suspend=n, address=1861
Double-click Startup_debug.bat to start Tomcat.
The configuration of the MyEclipse.
Right-click on the item and follow the actions shown
Check if you are listening, open the debug view
Browser input Address: Http://localhost:8080/servlettest/servlet/TestServlet
You can debug the normal breakpoint!!!
Debug breakpoint Debugging for a Tomcat project under MyEclipse