Premise: The source code of the Web project that runs on the remote server must be consistent with the local project, that is, the project that the remote Tomcat deploys is a native project that has been packaged in the past, and the native project has not changed.
Remote server-side
Server-side configuration Eclipse Debugger listening port, one of two ways, either
The first way:
Environment variables
Export jpda_address=9999
Start Tomcat
Start with SH catalina.sh jpda start
Note: Do not use startup.sh
Starting Tomcat with this command listens to the port set by the jpda_address and waits for the debugger to connect.
If Jpda_address is not configured, the default listener is 8000 port
The second way:
Configure $tomcat_home/bin/catalina.sh
Add the following line
java_opts= "$JAVA _opts-xdebug-xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9988"
Description: Server=y is the remote debugger (commonly used) that the target application listens to to be connected as a service, and suspend=y means that the target VM will be paused until the debugger application is connected (useful if debugging a startup error is required); suspend=n means that the target VM is not paused ; address=9988 listening port.
Start Tomcat
Start directly with startup.sh
By Ps-aux|grep Tomcat to view the launched Tomcat process, options such as the-xdebug that you just configured appear in the process information, proving that the configuration was successful
Native Debug Side Debugger configuration
Click the Debug button in local Eclipse and select Debug configurations ...., such as
After clicking on the options, pop up a window and double-click on the left remote Java application, as
Name: Custom, any name
Project: Web projects in native Eclipse, consistent with Web projects deployed on the remote server
Host: Remote server IP being debugged
Port: The value of the environment variable jpda_address in the remote server
Click Apply after the configuration is complete, then click on the lower right corner of the Debug,eclipse window to appear
Here ConnectionType we chose the standard (Socket Attach) mode of debugging, waiting for the progress bar to run, until the Consle red button turned gray, the server-side debugging is ready to complete
Test Debug Source Break point
Find a place to debug in the native eclipse source and hit a breakpoint
For example, I add a breakpoint to a method Testadd in a WebService service entry class
Test the interface, enter the breakpoint
For example, I test my own WebService interface.
Private StaticString endpoint = "HTTP://123.125.114.144:8080/JAVAUTILS/SERVICES/TESTSERVICE?WSDL"; Private StaticCall call =NULL; @BeforeClass Public Static voidInit () {Service service=NewService (); Try{ Call=(call) Service.createcall (); Call.settargetendpointaddress (endpoint); } Catch(serviceexception e) {e.printstacktrace (); }} @Test Public voidTestremotedebug () {String method= "Testadd"; //calling a remote method Try{String value= "TestValue"Object ret=Call.invoke (method,Newobject[] {value); System.out.println (Ret.tostring ()); } Catch(Axisfault e) {System.err.println (e.getfaultstring ()); } }
Performing unit tests, invoking the Testadd method of the server-side WebService service, passing in value value, when Eclipse enters the debug state, jumps to the 51 lines of the break point just now, so that it can F6 like natively, F5 to track and debug remote programs.
Note: The server-side configuration of the environment variable jpda_address is a port, but only the debugger listens on the port, but is not the same as the port that the deployment project in Tomcat runs on, the Web project run port is in the tomcat_home/conf/ <connector port= "8080" is configured in Server.xml, do not confuse.
This complete eclipse remote debugging step has been described clearly.
Summarize
The advantages and disadvantages of the standard (Socket Attach) mode for server-side monitoring:
Start the remote Java program and then start Eclipse Remote Debugging, and then debug the system as you normally would.
Disadvantage: Only Java program can be debugged after startup, unable to debug Java program startup process, if you want to debug the whole need to use another way, I will summarize into another article
Pros: You can always connect to a remote Java program for debugging
PS: This kind of debugging method is most commonly used
This article transferred from: http://javacrazyer.iteye.com/blog/1757429
Eclipse Remote Debugging (remote server-side monitoring)