Search code examples
javalinuxeclipsetomcat7remote-debugging

Two remote debugging methods


I have a ubuntu server and my app is running in tomcat7. Now I have two methods of remote debugging, as a learner I want to know what is the technical difference between the two or are they both same and I am missing something?

Method 1: open file /etc/default/tomcat7

#To enable remote debugging uncomment the following line.

#You will then be able to use a java debugger on port 8000.
#JAVA_OPTS="${JAVA_OPTS} -Xdebug Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

Method 2:

export CATALINA_HOME=/usr/share/tomcat7 export CATALINA_BASE=/var/lib/tomcat7/ export JPDA_ADDRESS=8090 export JRE_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64

now go to tomcat home folder /usr/share/tomcat7/bin and write the following line to run tomcat in debug mode.

#./catalina.sh jpda start

One more thing about method 2 which I came across is that when i start jpda and my tomcat service was also running on port 80, I was getting connection refused and when I stopped tomcat I was able to connect to 8090 remotely. WHy is that so?


Solution

  • Technically, they are the same, referring to the catalina.sh:

    if [ "$1" = "jpda" ] ; then
      if [ -z "$JPDA_TRANSPORT" ]; then
        JPDA_TRANSPORT="dt_socket"
      fi
      if [ -z "$JPDA_ADDRESS" ]; then
        JPDA_ADDRESS="8000"
      fi
      if [ -z "$JPDA_SUSPEND" ]; then
        JPDA_SUSPEND="n"
      fi
      if [ -z "$JPDA_OPTS" ]; then
        JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
      fi
      CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"
      shift
    fi
    

    On your second question, when stopping tomcat by shutdown.sh, the jpda port is still on listening which you can check with the linux command netstat or lsof. I've encountered with the same problem and not sure why tomcat doesn't deal with it.

    The error of connection refused on port 80 may have nothing to do with the jpda option. jdwp is a JVM flag, not only tomcat but also any other java applications can use it.