(十)Intellij 远程调试 a bug

来源:互联网 发布:软件开发的阶段 编辑:程序博客网 时间:2024/05/07 06:31

   接上篇文章:http://blog.csdn.net/lovesummerforever/article/details/50327445

   经常使用第一种远程调试方法,也就是不改动任何的配置文件,使用jpda默认端口8000,linux启动方式./catalina.sh jpda start ,报错误如下所示。


ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options.
Disconnected from server
Error occurred during initialization of VM
agent library failed to init: jdwp


   经查询错误如下:http://stackoverflow.com/questions/5993359/running-project-from-intellij-idea


   根据网上的提示,修改了catalina.sh 文件中的配置,配置如下

CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=10.255.223.148 -Dcom.sun.management.jmxremote.port=20152 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8001"


   经查看可知,是别人已经设置了jpda默认的启动端口8001,也就是第二种设置方式,这样直接启动tomcat的时候就已经启动了远程调试,而此时如果再使用这种方式./catalina.sh jpda start 启动,则相当于jpda端口已经被8001占用,因为这种方式默认启动的端口是8000。经过查看catalina.sh文件可以看到对一些参数的定义,如下所示。

 CATALINA_OPTS   (Optional) Java runtime options used when the "start",
#                   "run" or "debug" command is executed.
#                   Include here and not in JAVA_OPTS all options, that should
#                   only be used by Tomcat itself, not by the stop process,
#                   the version command etc.
#                   Examples are heap size, GC logging, JMX ports etc.




#   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
#                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
#                   and JPDA_SUSPEND are ignored. Thus, all required jpda
#                   options MUST be specified. The default is:
#
#                   -agentlib:jdwp=transport=$JPDA_TRANSPORT,
#                       address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND


#   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
#                   command is executed. The default is 8000.



   执行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


   所以当CATALINA_OPTS中已经配置了-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8001,再用./catalina.sh jpda start 启动就会重复操作,导致报错,解决办法就是删掉-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8001 中这句话配置,用./catalina.sh.jpda start启动,这样远程端口号默认为8000,否则就直接启动,使用的端口号为CATALINA_OPTS 中手动配置的8001。


总结:

   不运动不行啊,有规律的运动,有规律的生活~


1 0
原创粉丝点击