myeclipse tomcat 远程调试

来源:互联网 发布:iphone6s网络支持 编辑:程序博客网 时间:2024/05/29 15:27
一、Linux环境
1.修改Linux上Tomcat的catalina.sh,第一行添加 declare -x CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8085"
2:在eclipse中, 右键需要调试的工程debug asdebug configurationsnew 一个java remote application,填写如下图,信息填写正确后,点击debug即可进行远程调试了。
3:运行Linux上的tomcat/bin/catalina.sh启动tomcat,
命令如下:当前tomcatbin目录下
输入:./catalina.sh run (这样可以看到Tomcat的信息运行信息)
如果提示没有权限,以root身份设置权限:chmod +x *.*
Listening for transport dt_socket at address: 8000" 这样的信息,说明调试端口已经被监听
4:在windows上的eclipse中点 "Run->Debug..."选中刚才新建的,点"Debug",如果一切正确就没有提示。此后你在代码中设置的断点就会执行。
 
5:关于修改源代码,由于java本身的JPDA机制,远程代码运行效果会被及时更新,但是并不能更新远程服务器上的代码,这一点要注意.

二、window 环境

作为一名开发人员多多少少会遇到各种问题,在众多问题中或许你也会遇到:在本地都运行的好好的,可是发布到服务器后怎么就出问题了呢?出现这种问题的原因有很多种,可到底是什么原因引起的呢?我们开发过程中通常都是通过myeclipse的debug来查找原因,总不可能在服务器上安装myeclipse来调试程序吧?那怎么办?没关系,还好有jpda(全称JavaTM Platform Debugger Architecture)这个东东,需要在tomcat的启动文件(startup.bat)中配置jpda,为了不修改原有的文件,我们新增一个startup_debug.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.

if "%OS%" == "Windows_NT" setlocal
rem ---------------------------------------------------------------------------
rem Start script for the CATALINA Server
rem
rem $Id: startup.bat 895392 2010-01-03 14:02:31Z kkolinko $
rem ---------------------------------------------------------------------------

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

set JPDA_TRANSPORT=dt_socket
set JPDA_ADDRESS=8000
set JPDA_SUSPEND=n

call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%

:end

内容与startup.bat几乎一致,标黑的脚本为新增的脚本,启动时启动startup_debug.bat即可

参数解释:

jpda_transport=dt_socket(JPDA front-end和back-end之间的传输方法。dt_socket表示使用套接字传输。)

jpad_address=8000(JVM在8000端口上监听请求。)

jpda_suspend=n(n表示直接启动监听端口和JVM,y表示启动的JVM会暂停等待,直到调试器连接上。)

 

配置本地的myeclipse

 右键需要调试的工程debug asdebug configurationsnew 一个java remote application,填写如下图,信息填写正确后,点击debug即可进行远程调试了。

 


0 0