How to use Idea to debug Java code remotely

Server configuration

  First, we need to make the remote server support the remote debugging function by appending specific JVM parameters to the project startup item. The parameters are as follows:

  • Later than JDK 1.4.X version
    1
    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=4001
  • JDK 1.4.X version
    1
    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4001
  • JDK 1.3.X or earlier
    1
    -Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4001


    You can use different startup parameters according to different JDK versions. I am using Tomcat 7 + Java 7, just set the JAVA_OPTS node in catalina.bat (linux environment setting catalina.sh), "4001" in "address=4001" is the debugging port, you can set it according to your needs ( Friendly reminder: Do not occupy the port of the website, it may cause an error when the project starts).

 IDE configuration

  Then, just configure the client. Idea's client configuration is very simple as shown in the following figure:

Click Edit Configurations to enter the Run/Debug Configurations interface:

Click the "+" sign in the upper left corner, you can find the "Remote" option in the drop-down box. After selecting OK, the right area appears. First, configure the remote server address to be debugged in the HOST (mark 2) box, and then debug the port. Debug port number in Mad (mark 3) (the port number here is the same as the port number on the server side, in this example it is "4001"), click OK.

Debug steps

  Finally, enter the debugging process, the debugging of the entire project is also very simple, click the debug button in the figure below, when the console window prints out "Connected to the target VM, address: 127.0.0.1:4001', transport: 'socket'" That means the link is successful:

  Of course, there will be unfortunate situations, such as:

  • Server port restrictions, such as the server blocking the "4001" port, will cause remote debugging to fail;
  • Inconsistency between local code and remote code will also cause remote code debugging to fail;

After the startup is successful, you can happily debug remote code just like debugging local code.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324699004&siteId=291194637
Recommended