Eclipse-Tomcat-远程端口调试

Eclipse不仅可以调试本地代码,也可以远程调试部署在服务器上的项目代码,这点在调试本地无法重现的问题上意义尤为重大。
Window中修改 startup.bat文件,添加:

SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8005 
//可不添加
echo tomcat ready to debug address 8055
SET JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF-8
参数说明:

-Xdebug : 启用调试模式

-Xrunjdwp: 加载JVM的JPDA参考实现库

transport=dt_socket :Socket连接,可选dt_shmem 通过共享内存的方式连接到调试服务器

address=8000 :调试服务器监听的端口

server=y : 是否是服务器端,n为客户端

suspend=n : 启动过程是否加载暂停,y为启动时暂停,方便调试启动过程

启动tomcat,看看tomcat是否启动成功,

如果启动成功,tomcat日志文件(catalina.out)中会有如下输出:

Listening for transport dt_socket at address: 8000

使用eclipse调试:

点击debug,就可进行调试了

剩下的就和普通调试一样了。断点直接在源代码中添加就行

5、可能出现的连接问题:

Failed to connect to remote VM. Connection refused.

Connection refused: connect。

出现如图所示的情况可能是已经建立了一个连接了。

附件: startup.bat 源码

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

rem ---------------------------------------------------------------------------
rem Start script for the CATALINA Server
rem ---------------------------------------------------------------------------

setlocal

SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8005 
echo tomcat ready to debug address 8055
SET JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF-8

rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%"
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

:end


 上一篇
HttpClient 发送get post请求和数据解析及详解 HttpClient 发送get post请求和数据解析及详解
HttpClient 发送get post 请求和数据解析以及使用详解 HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们再讨论),它不仅是客户端发送Http请求变得容易,而且也方便
2017-02-21
下一篇 
浅析VO、DTO、DO、PO的概念、区别和用处 浅析VO、DTO、DO、PO的概念、区别和用处
概念:VO(View Object):视图对象,用于展示层,它的作用是把某个指定页面(或组件)的所有数据封装起来。 DTO(Data Transfer Object):数据传输对象,这个概念来源于J2EE的设计模式,原来的目的是为了EJ
2016-12-23
  目录