java - tomcat remote debug mode in linux -
i setting tomcat in debug mode. tomcat server running on different machine , working on different machine.
before starting tomcat executing following linux command.
iptables -i input -m state --state new -m tcp -p tcp --dport 9003 -j accept export jpda_address=9003 export jpda_transport=dt_socket export jpda_suspend=n bin/catalina.sh jpda start
in eclipse providing ip address of remote machine , port number 9003.
my ./catalina.sh file given below. still not able see green color debug pointers @ breakpoint. ? eclipse doesn't throw exception while connecting remote machine. earlier throwing 'connection failed' once executed following command rectified, not able see breakpoints after have given breakpoints.
iptables -i input -m state --state new -m tcp -p tcp --dport 9003 -j accept
my cataline.sh
file.
#!/bin/sh # licensed apache software foundation (asf) under 1 or more # contributor license agreements. see notice file distributed # work additional information regarding copyright ownership. # asf licenses file under apache license, version 2.0 # (the "license"); may not use file except in compliance # license. may obtain copy of license @ # # http://www.apache.org/licenses/license-2.0 # # unless required applicable law or agreed in writing, software # distributed under license distributed on "as is" basis, # without warranties or conditions of kind, either express or implied. # see license specific language governing permissions , # limitations under license. # ----------------------------------------------------------------------------- # control script catalina server # # environment variable prerequisites # # not set variables in script. instead put them script # setenv.sh in catalina_base/bin keep customizations separate. # # catalina_home may point @ catalina "build" directory. # # catalina_base (optional) base directory resolving dynamic portions # of catalina installation. if not present, resolves # same directory catalina_home points to. # # catalina_out (optional) full path file stdout , stderr # redirected. # default $catalina_base/logs/catalina.out # # catalina_opts (optional) java runtime options used when "start", # "run" or "debug" command executed. # include here , not in java_opts options, should # used tomcat itself, not stop process, # version command etc. # examples heap size, gc logging, jmx ports etc. # # catalina_tmpdir (optional) directory path location of temporary directory # jvm should use (java.io.tmpdir). defaults # $catalina_base/temp. # # java_home must point @ java development kit installation. # required run "debug" argument. # # jre_home must point @ java runtime installation. # defaults java_home if empty. if jre_home , java_home # both set, jre_home used. # # java_opts (optional) java runtime options used when command # executed. # include here , not in catalina_opts options, # should used tomcat , stop process, # version command etc. # options should go catalina_opts. # # java_endorsed_dirs (optional) lists of of colon separated directories # containing jars in order allow replacement of apis # created outside of jcp (i.e. dom , sax w3c). # can used update xml parser implementation. # defaults $catalina_home/endorsed. # # jpda_transport (optional) jpda transport used when "jpda start" # command executed. default "dt_socket". # # jpda_address (optional) java runtime options used when "jpda start" # command executed. default 8000. # # jpda_suspend (optional) java runtime options used when "jpda start" # command executed. specifies whether jvm should suspend # execution after startup. default "n". # # jpda_opts (optional) java runtime options used when "jpda start" # command executed. if used, jpda_transport, jpda_address, # , jpda_suspend ignored. thus, required jpda # options must specified. default is: # # -agentlib:jdwp=transport=$jpda_transport, # address=$jpda_address,server=y,suspend=$jpda_suspend # # catalina_pid (optional) path of file should contains pid # of catalina startup java process, when start (fork) # used # # logging_config (optional) override tomcat's logging config file # example (all 1 line) # logging_config="-djava.util.logging.config.file=$catalina_base/conf/logging.properties" # # logging_manager (optional) override tomcat's logging manager # example (all 1 line) # logging_manager="-djava.util.logging.manager=org.apache.juli.classloaderlogmanager" # ----------------------------------------------------------------------------- # os specific support. $var _must_ set either true or false. cygwin=false darwin=false os400=false case "`uname`" in cygwin*) cygwin=true;; darwin*) darwin=true;; os400*) os400=true;; esac # resolve links - $0 may softlink prg="$0" while [ -h "$prg" ]; ls=`ls -ld "$prg"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; prg="$link" else prg=`dirname "$prg"`/"$link" fi done # standard environment variables prgdir=`dirname "$prg"` # set catalina_home if not set [ -z "$catalina_home" ] && catalina_home=`cd "$prgdir/.." >/dev/null; pwd` # copy catalina_base catalina_home if not set [ -z "$catalina_base" ] && catalina_base="$catalina_home" # ensure user defined classpath variables not used on startup, # allow them specified in setenv.sh, in rare case when needed. classpath= if [ -r "$catalina_base/bin/setenv.sh" ]; . "$catalina_base/bin/setenv.sh" elif [ -r "$catalina_home/bin/setenv.sh" ]; . "$catalina_home/bin/setenv.sh" fi # cygwin, ensure paths in unix format before touched if $cygwin; [ -n "$java_home" ] && java_home=`cygpath --unix "$java_home"` [ -n "$jre_home" ] && jre_home=`cygpath --unix "$jre_home"` [ -n "$catalina_home" ] && catalina_home=`cygpath --unix "$catalina_home"` [ -n "$catalina_base" ] && catalina_base=`cygpath --unix "$catalina_base"` [ -n "$classpath" ] && classpath=`cygpath --path --unix "$classpath"` fi # os400 if $os400; # set job priority standard interactive (interactive - 6) using # interactive priority - 6, helper threads respond requests # running @ same priority interactive jobs. command='chgjob job('$jobname') runpty(6)' system $command # enable multi threading export qibm_multi_threaded=y fi # standard java environment variables if $os400; # -r work on os400 if files are: # 1. owned user # 2. owned primary group of user # not work if user belongs in secondary groups . "$catalina_home"/bin/setclasspath.sh else if [ -r "$catalina_home"/bin/setclasspath.sh ]; . "$catalina_home"/bin/setclasspath.sh else echo "cannot find $catalina_home/bin/setclasspath.sh" echo "this file needed run program" exit 1 fi fi # add on jar files classpath if [ ! -z "$classpath" ] ; classpath="$classpath": fi classpath="$classpath""$catalina_home"/bin/bootstrap.jar if [ -z "$catalina_out" ] ; catalina_out="$catalina_base"/logs/catalina.out fi if [ -z "$catalina_tmpdir" ] ; # define java.io.tmpdir use catalina catalina_tmpdir="$catalina_base"/temp fi # add tomcat-juli.jar classpath # tomcat-juli.jar can over-ridden per instance if [ -r "$catalina_base/bin/tomcat-juli.jar" ] ; classpath=$classpath:$catalina_base/bin/tomcat-juli.jar else classpath=$classpath:$catalina_home/bin/tomcat-juli.jar fi # bugzilla 37848: when no tty available, don't output console have_tty=0 if [ "`tty`" != "not tty" ]; have_tty=1 fi # cygwin, switch paths windows format before running java if $cygwin; java_home=`cygpath --absolute --windows "$java_home"` jre_home=`cygpath --absolute --windows "$jre_home"` catalina_home=`cygpath --absolute --windows "$catalina_home"` catalina_base=`cygpath --absolute --windows "$catalina_base"` catalina_tmpdir=`cygpath --absolute --windows "$catalina_tmpdir"` classpath=`cygpath --path --windows "$classpath"` java_endorsed_dirs=`cygpath --path --windows "$java_endorsed_dirs"` fi # set juli logmanager config file if present , override has not been issued if [ -z "$logging_config" ]; if [ -r "$catalina_base"/conf/logging.properties ]; logging_config="-djava.util.logging.config.file=$catalina_base/conf/logging.properties" else # bugzilla 45585 logging_config="-dnop" fi fi if [ -z "$logging_manager" ]; logging_manager="-djava.util.logging.manager=org.apache.juli.classloaderlogmanager" fi # uncomment following line make umask available when using # org.apache.catalina.security.securitylistener #java_opts="$java_opts -dorg.apache.catalina.security.securitylistener.umask=`umask`" # ----- execute requested command ----------------------------------------- # bugzilla 37848: output if have tty if [ $have_tty -eq 1 ]; echo "using catalina_base: $catalina_base" echo "using catalina_home: $catalina_home" echo "using catalina_tmpdir: $catalina_tmpdir" if [ "$1" = "debug" ] ; echo "using java_home: $java_home" else echo "using jre_home: $jre_home" fi echo "using classpath: $classpath" if [ ! -z "$catalina_pid" ]; echo "using catalina_pid: $catalina_pid" fi fi if [ "$1" = "jpda" ] ; if [ -z "$jpda_transport" ]; jpda_transport="dt_socket" fi if [ -z "$jpda_address" ]; jpda_address="8000" fi if [ -z "$jpda_suspend" ]; jpda_suspend="n" fi if [ -z "$jpda_opts" ]; jpda_opts="-agentlib:jdwp=transport=$jpda_transport,address=$jpda_address,server=y,suspend=$jpda_suspend" fi catalina_opts="$catalina_opts $jpda_opts" shift fi if [ "$1" = "debug" ] ; if $os400; echo "debug command not available on os400" exit 1 else shift if [ "$1" = "-security" ] ; if [ $have_tty -eq 1 ]; echo "using security manager" fi shift exec "$_runjdb" "$logging_config" $logging_manager $java_opts $catalina_opts \ -djava.endorsed.dirs="$java_endorsed_dirs" -classpath "$classpath" \ -sourcepath "$catalina_home"/../../java \ -djava.security.manager \ -djava.security.policy=="$catalina_base"/conf/catalina.policy \ -dcatalina.base="$catalina_base" \ -dcatalina.home="$catalina_home" \ -djava.io.tmpdir="$catalina_tmpdir" \ org.apache.catalina.startup.bootstrap "$@" start else exec "$_runjdb" "$logging_config" $logging_manager $java_opts $catalina_opts \ -djava.endorsed.dirs="$java_endorsed_dirs" -classpath "$classpath" \ -sourcepath "$catalina_home"/../../java \ -dcatalina.base="$catalina_base" \ -dcatalina.home="$catalina_home" \ -djava.io.tmpdir="$catalina_tmpdir" \ org.apache.catalina.startup.bootstrap "$@" start fi fi elif [ "$1" = "run" ]; shift if [ "$1" = "-security" ] ; if [ $have_tty -eq 1 ]; echo "using security manager" fi shift eval exec "\"$_runjava\"" "\"$logging_config\"" $logging_manager $java_opts $catalina_opts \ -djava.endorsed.dirs="\"$java_endorsed_dirs\"" -classpath "\"$classpath\"" \ -djava.security.manager \ -djava.security.policy=="\"$catalina_base/conf/catalina.policy\"" \ -dcatalina.base="\"$catalina_base\"" \ -dcatalina.home="\"$catalina_home\"" \ -djava.io.tmpdir="\"$catalina_tmpdir\"" \ org.apache.catalina.startup.bootstrap "$@" start else eval exec "\"$_runjava\"" "\"$logging_config\"" $logging_manager $java_opts $catalina_opts \ -djava.endorsed.dirs="\"$java_endorsed_dirs\"" -classpath "\"$classpath\"" \ -dcatalina.base="\"$catalina_base\"" \ -dcatalina.home="\"$catalina_home\"" \ -djava.io.tmpdir="\"$catalina_tmpdir\"" \ org.apache.catalina.startup.bootstrap "$@" start fi elif [ "$1" = "start" ] ; if [ ! -z "$catalina_pid" ]; if [ -f "$catalina_pid" ]; if [ -s "$catalina_pid" ]; echo "existing pid file found during start." if [ -r "$catalina_pid" ]; pid=`cat "$catalina_pid"` ps -p $pid >/dev/null 2>&1 if [ $? -eq 0 ] ; echo "tomcat appears still running pid $pid. start aborted." exit 1 else echo "removing/clearing stale pid file." rm -f "$catalina_pid" >/dev/null 2>&1 if [ $? != 0 ]; if [ -w "$catalina_pid" ]; cat /dev/null > "$catalina_pid" else echo "unable remove or clear stale pid file. start aborted." exit 1 fi fi fi else echo "unable read pid file. start aborted." exit 1 fi else rm -f "$catalina_pid" >/dev/null 2>&1 if [ $? != 0 ]; if [ ! -w "$catalina_pid" ]; echo "unable remove or write empty pid file. start aborted." exit 1 fi fi fi fi fi shift touch "$catalina_out" if [ "$1" = "-security" ] ; if [ $have_tty -eq 1 ]; echo "using security manager" fi shift eval "\"$_runjava\"" "\"$logging_config\"" $logging_manager $java_opts $catalina_opts \ -djava.endorsed.dirs="\"$java_endorsed_dirs\"" -classpath "\"$classpath\"" \ -djava.security.manager \ -djava.security.policy=="\"$catalina_base/conf/catalina.policy\"" \ -dcatalina.base="\"$catalina_base\"" \ -dcatalina.home="\"$catalina_home\"" \ -djava.io.tmpdir="\"$catalina_tmpdir\"" \ org.apache.catalina.startup.bootstrap "$@" start \ >> "$catalina_out" 2>&1 "&" else eval "\"$_runjava\"" "\"$logging_config\"" $logging_manager $java_opts $catalina_opts \ -djava.endorsed.dirs="\"$java_endorsed_dirs\"" -classpath "\"$classpath\"" \ -dcatalina.base="\"$catalina_base\"" \ -dcatalina.home="\"$catalina_home\"" \ -djava.io.tmpdir="\"$catalina_tmpdir\"" \ org.apache.catalina.startup.bootstrap "$@" start \ >> "$catalina_out" 2>&1 "&" fi if [ ! -z "$catalina_pid" ]; echo $! > "$catalina_pid" fi echo "tomcat started." elif [ "$1" = "stop" ] ; shift sleep=5 if [ ! -z "$1" ]; echo $1 | grep "[^0-9]" >/dev/null 2>&1 if [ $? -gt 0 ]; sleep=$1 shift fi fi force=0 if [ "$1" = "-force" ]; shift force=1 fi if [ ! -z "$catalina_pid" ]; if [ -f "$catalina_pid" ]; if [ -s "$catalina_pid" ]; kill -0 `cat "$catalina_pid"` >/dev/null 2>&1 if [ $? -gt 0 ]; echo "pid file found no matching process found. stop aborted." exit 1 fi else echo "pid file empty , has been ignored." fi else echo "\$catalina_pid set specified file not exist. tomcat running? stop aborted." exit 1 fi fi eval "\"$_runjava\"" $logging_manager $java_opts \ -djava.endorsed.dirs="\"$java_endorsed_dirs\"" -classpath "\"$classpath\"" \ -dcatalina.base="\"$catalina_base\"" \ -dcatalina.home="\"$catalina_home\"" \ -djava.io.tmpdir="\"$catalina_tmpdir\"" \ org.apache.catalina.startup.bootstrap "$@" stop # stop failed. shutdown port disabled? try normal kill. if [ $? != 0 ]; if [ ! -z "$catalina_pid" ]; echo "the stop command failed. attempting signal process stop through os signal." kill -15 `cat "$catalina_pid"` >/dev/null 2>&1 fi fi if [ ! -z "$catalina_pid" ]; if [ -f "$catalina_pid" ]; while [ $sleep -ge 0 ]; kill -0 `cat "$catalina_pid"` >/dev/null 2>&1 if [ $? -gt 0 ]; rm -f "$catalina_pid" >/dev/null 2>&1 if [ $? != 0 ]; if [ -w "$catalina_pid" ]; cat /dev/null > "$catalina_pid" # if tomcat has stopped don't try , force stop empty pid file force=0 else echo "the pid file not removed or cleared." fi fi echo "tomcat stopped." break fi if [ $sleep -gt 0 ]; sleep 1 fi if [ $sleep -eq 0 ]; if [ $force -eq 0 ]; echo "tomcat did not stop in time. pid file not removed. aid diagnostics thread dump has been written standard out." kill -3 `cat "$catalina_pid"` fi fi sleep=`expr $sleep - 1 ` done fi fi kill_sleep_interval=5 if [ $force -eq 1 ]; if [ -z "$catalina_pid" ]; echo "kill failed: \$catalina_pid not set" else if [ -f "$catalina_pid" ]; pid=`cat "$catalina_pid"` echo "killing tomcat pid: $pid" kill -9 $pid while [ $kill_sleep_interval -ge 0 ]; kill -0 `cat "$catalina_pid"` >/dev/null 2>&1 if [ $? -gt 0 ]; rm -f "$catalina_pid" >/dev/null 2>&1 if [ $? != 0 ]; if [ -w "$catalina_pid" ]; cat /dev/null > "$catalina_pid" else echo "the pid file not removed." fi fi # set 0 else warning issued process still running kill_sleep_interval=0 echo "the tomcat process has been killed." break fi if [ $kill_sleep_interval -gt 0 ]; sleep 1 fi kill_sleep_interval=`expr $kill_sleep_interval - 1 ` done if [ $kill_sleep_interval -gt 0 ]; echo "tomcat has not been killed yet. process might waiting on system call or might uninterruptible." fi fi fi fi elif [ "$1" = "configtest" ] ; eval "\"$_runjava\"" $logging_manager $java_opts \ -djava.endorsed.dirs="\"$java_endorsed_dirs\"" -classpath "\"$classpath\"" \ -dcatalina.base="\"$catalina_base\"" \ -dcatalina.home="\"$catalina_home\"" \ -djava.io.tmpdir="\"$catalina_tmpdir\"" \ org.apache.catalina.startup.bootstrap configtest result=$? if [ $result -ne 0 ]; echo "configuration error detected!" fi exit $result elif [ "$1" = "version" ] ; "$_runjava" \ -classpath "$catalina_home/lib/catalina.jar" \ org.apache.catalina.util.serverinfo else echo "usage: catalina.sh ( commands ... )" echo "commands:" if $os400; echo " debug start catalina in debugger (not available on os400)" echo " debug -security debug catalina security manager (not available on os400)" else echo " debug start catalina in debugger" echo " debug -security debug catalina security manager" fi echo " jpda start start catalina under jpda debugger" echo " run start catalina in current window" echo " run -security start in current window security manager" echo " start start catalina in separate window" echo " start -security start in separate window security manager" echo " stop stop catalina, waiting 5 seconds process end" echo " stop n stop catalina, waiting n seconds process end" echo " stop -force stop catalina, wait 5 seconds , use kill -kill if still running" echo " stop n -force stop catalina, wait n seconds , use kill -kill if still running" echo " configtest run basic syntax check on server.xml - check exit code result" echo " version version of tomcat running?" echo "note: waiting process end , use of -force option require \$catalina_pid defined" exit 1 fi
Comments
Post a Comment