tomcat+myeclipse配置遠程調試

做爲一名開發人員多多少少會遇到各類問題,在衆多問題中或許你也會遇到:在本地都運行的好好的,但是發佈到服務器後怎麼就出問題了呢?出現這種問題的緣由有不少種,可究竟是什麼緣由引發的呢?咱們開發過程當中一般都是經過myeclipse的debug來查找緣由,總不可能在服務器上安裝myeclipse來調試程序吧?那怎麼辦?不要緊,還好有jpda(全稱JavaTM Platform Debugger Architecture)這個東東,須要在tomcat的啓動文件(startup.bat)中配置jpda,爲了避免修改原有的文件,咱們新增一個startup_debug.bat,內容以下:java

@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.web

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 ---------------------------------------------------------------------------express

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
:okHomeapache

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

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
:doneSetArgsapp

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

call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%eclipse

:endsocket

內容與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便可進行遠程調試了。

 

 

 注意:一、調試時須要保持本地代碼和服務器上代碼一致

          二、確認防火牆關閉

相關文章
相關標籤/搜索