Tuesday, July 8, 2014

tomcat remote debugging using netbeans

Tomcat:

tomcat/bin/catalina.sh checks for jpda argument. If jpda argument is passed then if other required variables are not available, it automatically sets defaults values for those variables. Below is the snippet of /mnt/eprint/tomcat/bin/catalina.sh file:

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


 /mnt/eprint/tomcat/bin/startup.sh run the command "catalina.sh start $@". $@ represents all the argument passed to startup.sh. /mnt/eprint/tomcat/bin/startup.sh has the below snippet:

PRGDIR=`dirname "$PRG"`
EXECUTABLE=catalina.sh

.
.
.
exec "$PRGDIR"/"$EXECUTABLE" start "$@" 


To start tomcat in remote debug mode the command run by /mnt/eprint/tomcat/bin/startup.sh should look like "catalina.sh jpda start $@". After doing the changes /mnt/eprint/tomcat/bin/startup.sh looks like below:

PRGDIR=`dirname "$PRG"`
EXECUTABLE=catalina.sh

.
.
.
exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"


If you don't want catalina.sh to set default values for jpda parameters then you can even declare them in the /mnt/eprint/tomcat/bin/startup.sh as below:

export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket


Netbeans:

To debug an externally started application call Debug . Attach Debugger. Select the Java Debugger
(JPDA) and use SocketAttach as connector. Additionally, you indicate the host’s name on which the
application runs, the port number on which the application accepts requests, as well as a timeout.
Press OK after doing the settings.
























No comments:

Post a Comment

Followers