Java Remote Debug (Idea Remoting)

Source: Internet
Author: User

Overview

For the debugging of distributed system do not know what a good way for everyone. For me, before I know the remote debugging method is to play a variety of logs in the code, and then redeploy, on-line, debugging, it is more time-consuming. Today let's learn about Java remote Debugging This is a cool feature, this article takes IntelliJ idea as an example to explain how to use remote debugging. Take the thrift introductory tutorial as an example of the program used in this article. This program consists of the thrift server and the client. Describe the issues that remote debugging needs to address:

The service-side program runs on a remote server, and we can set breakpoints in the local service-side code (provided the local code must be consistent with the code running on the remote server) whenever there is a request to the remote server to be able to locally know the internal state of the remote service side at this time.

Follow the steps below to explain how remote Debug.

Running service-side code with specific JVM parameters

To enable remote debugging for code running on a remote server, you must start with a specific JVM parameter, which is:

-Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=${debug_port}

Where the ${debug_port} is user-defined, for the debug port, this example takes port 5555 as an example.

Configuration Step 1. Local idea Configuration

Open IntelliJ idea, in the top right place select "Edit configurations ...", go in and click on the + number, select "Remote", followed by just fill in the contents of the red box, where host is the remote code to run the machine ip/hostname, Port is the debug_port specified in the previous step, this example is 5555

Then click Apply and then click OK

Note: Where host is the remote server address port is a custom port

Preserve JVM parameters (used when server is configured)

Or

2. Server Configuration
Modify startup script (start.sh)--field JVM parameters
Nohup/usr/java/jdk1.8.0_40/bin/java-jar-xdebug-xrunjdwp:transport=dt_socket,address=9527,server=y,suspend=y Appserver.jar--spring.config.locaton=./application.yml--logging.config=./logback.xml &

Note:

Start Debug mode

Now in the previous step select "Edit configurations ..." drop-down box location Select the remote name created in the previous step, then click on the Debug button on the right (long as the bug that), look at the console log, if there is a similar "Connected to the Target VM, Address: ' xx.xx.xx.xx:5555 ', Transport: ' socket ' , means the connection was successful.

Set breakpoints, start debugging

The remote debug mode is turned on and can now break points in the code that needs to be debugged, such as:

, if there is a yes in the breakpoint, the selected breakpoint is correct.

Now send a local request to the remote server, look at the local console bug interface, to debugger this tab, you can see the current remote service's internal state (various variables) has been shown, and at the point where the breakpoint was just set, also shows the value of the row variable.

Java Remote Debug (Idea Remoting)

Java Remote Debug (Idea Remoting)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.