idea14远程调试linux下的tomcat

进入到idea的tomcat的run/debug配置,新建个remote tomcat,然后填写相关信息,如上图(注意远程调试端口)。

再选择Startup/Connection,如下图所示:

到此,idea已经配置好了,接下来将图上说的那段拷贝到远程的tomcat的catalina.sh文件中。

登陆到远程服务器,进入到tomcat的bin目录下,vi打开catalina.sh文件:

找到第一个JAVA_OPTS,添加:

JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,address=54531,suspend=n,server=y"或者

CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,address=54531,suspend=n,server=y"
填一个即可。

重启下tomcat。

netstat -an | grep 55555,查看下55555端口是否打开,打开说民设置成功。

这样既可以使用idea远程调试了。

另外最好的方式就是不要去改动默认的sh文件,那就是自己写的debug.sh

将startup.sh拷贝一份,改名为debug.sh.

打开,内容如下:

#!/bin/sh

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------

# Better OS/400 detection: see Bugzilla 31132
os400=false
case "`uname`" in
OS400*) os400=true;;
esac

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

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

# Check that target executable exists
if $os400; then
  # -x will Only work on the os400 if the files are:
  # 1. owned by the user
  # 2. owned by the PRIMARY group of the user
  # this will not work if the user belongs in secondary groups
  eval
else
  if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
    echo "Cannot find $PRGDIR/$EXECUTABLE"
    echo "The file is absent or does not have execute permission"
    echo "This file is needed to run this program"
    exit 1
  fi
fi
export CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,address=55555,suspend=n,server=y"

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

 增加红色部分即可。

root@×××:/usr/local/tomcat/bin# sh debug.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/lib/jdk/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
root@×××:/usr/local/tomcat/bin# netstat -ano|grep 55555
tcp        0      0 0.0.0.0:55555           0.0.0.0:*               LISTEN      off (0.00/0/0)
root@×××:/usr/local/tomcat/bin#
如果按上面步骤执行后,看见设置的端口已经被监听,说明配置成功。

 

posted on 2015-03-23 11:38  jec  阅读(1642)  评论(0编辑  收藏  举报

导航