We are ready to start debugging an application remotely. Let's do it step by step:
- 1. Create a Java project with a simple class
- We create a simple class for debugging purpose. Listing 1 shows the sample code.
Listing 1. Sample code for debugging
package com.ibm.developerWorks.debugtest;2. Set a breakpoint
public class test {
public static void main(String[] args) {
System.out.println("This is a test.");
}
}3. Debug the application remotely
- Copy the JAR file to the appropriate location on the remote computer, or even the same machine, invoke the debug server, and then attach a client to it. The simple Java application can act as a debug server or client. Depending on the configuration, you can choose either Socket Attach or Socket Listen connection type in Eclipse. Learn how to run the application as a server or client in the following two sections.
- 3.1 The simple Java application can act as a debug server
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address="8000" -jar
test.jar- Set the Eclipse is debug client

- 3.2 Eclipse is debug server

- Run the client as
java -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8000,suspend=y
-jar test.jarThis article illustrated how to use the Eclipse built-in remote Java
application configuration type to perform application debugging
remotely. It introduced how to set up a Java application to invoke
remote debugging and helped you understand the connectors Eclipse
provides. Finally, you learned how to apply this technology to your
projects.

0 comments:
Post a Comment