Use Idea remote debugging Java code

  • purpose

    • When an error occurs on the server code, the log to analyze too much trouble, may sometimes unable to locate the exact cause of the problem; it is the FBI by remote debug server code, accurately and efficiently.
  • Server configuration

    • First of all, we want to let the remote server supports remote debugging feature, additional specific JVM arguments on the project can start, parameters are as follows:
      • Command line arguments for running remote JVM (later than JDK 1.4.X versions) 
      • -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9508

         

      • JDK 1.4.X versions
      • -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9508

         

      • JDK 1.3.X or early release
      • -Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9508

         

    • The first: Spring boot -jar by Java  -agentlib: Transport JDWP = = the dt_socket, Server Y =, = n-Suspend, address = 9508 xxx.jar &, configured to startup command line;
    • Second: Set JAVA_OPTS nodes can now catalina.bat (linux environment settings catalina.sh) in. - Configure Tomcat server
      to the next $ TOMCAT_HOME / bin directory:
      vi catalina.sh
      #在# OS specific support.上面添加
      export JAVA_OPTS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9508'
  • Idea Configuration

    • Click Edit Configurations, you can enter the Run / Debug Configurations interface, configure remote:
  • Start Debugging

    • Click below identifies the debug start mark, will start a successful output on the console panel: Connected to at The target VM, address: '140.143.29.146:9508', Transport: 'socket'
  • Possible problems and solutions

    • problem:
      • 第一个问题:Error running 'remote-ms-collection': Unable to open debugger port (XXXX:9508): java.net.ConnectException "Connection timed out: connect"
      • The second question: IP and port number no problem but "Connection refused"
    • Solution:
      • Open the relevant ports:
      • vi /etc/sysconfig/iptables 
        
        #在-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT之后添加
        
        -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
        
        -A INPUT -m state --state NEW -m tcp -p tcp --dport 9508 -j ACCEPT
        
        

         

      • Restart the firewall:
        service iptables restart
      • Also OK if troublesome, or to turn off the firewall security less demanding direct:
        service iptables stop
      • Restart Service
  • Note: The remote debug while ensuring that a client can only connect

Reference Address:

https://www.cnblogs.com/krockey/p/5056945.html

https://www.jianshu.com/p/f902ac5d29e4

https://www.jianshu.com/p/aa63146d7e0b

Published 75 original articles · won praise 48 · Views 350,000 +

Guess you like

Origin blog.csdn.net/KingJin_CSDN_/article/details/84074127