Java remote debug(on startup)

If you use intellij, you can use the function "Attach to local process..." if it doesn't work then you need to set up a remote debug to connect to your remote program(can be on the same machine or actual remote machine).

Debugger side:

a. Create a new remote debug configure

b. Select "Socket", put localhost for local mahine or the actual host name if it's actual a remote host, host can be whatever as long as it's not occupied on remote host yet

c. Start the java program with options of below, normally use the first option, if you need to debug right on startup then you need to second option.

####remote debug####

-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8889

####remote debug on startup#####

  (Suspend=y which means program will suspend until connected to debugger, so debugger can execute right from the every beginnig of the program)

   -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=8889

e.g. java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8889 -cp . com.lefeng.MainClassName

原文地址:https://www.cnblogs.com/glf2046/p/6207990.html