远程调试tomcat

<p>
</p>
<p class="MsoNormal"><span lang="ZH">在做远程调试时,在</span><span lang="EN-US">windows</span><span lang="ZH">系统和非</span><span lang="EN-US">windows</span><span lang="ZH">系统下的配置,</span><span lang="EN-US">Tomcat</span><span lang="ZH">中会有所差别</span><span lang="EN-US">,</span><span lang="ZH">具体如下</span><span>:</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="ZH">第一步、配置</span><span lang="EN-US">tomcat</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="ZH">一、在</span><span lang="EN-US">windows</span><span lang="ZH">系统中</span><span>:</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="ZH">打开</span><span lang="EN-US">%CATALINE_HOME%/bin</span><span lang="ZH">下的文件</span><span lang="EN-US">catalina.bat</span><span lang="ZH">,加入下面这行</span><span>:</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US">set CATALINA_OPTS=-server -Xdebug
-Xnoagent
-Djava.compiler=NONE-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787</span><span>。</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="ZH">其中</span><span lang="EN-US">address=8787</span><span lang="ZH">是没被使用的端口号。连接方式有两种,为</span><span lang="EN-US">dt_shmem</span><span lang="ZH">和</span><span lang="EN-US">dt_socket</span><span lang="ZH">,分别表示本机调试和远程调试。</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="ZH">二、在非</span><span lang="EN-US">windows</span><span lang="ZH">系统中:</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="ZH">还需要把</span><span lang="EN-US">% CATALINE_HOME %/bin/startup.sh</span><span lang="ZH">中的最后一行</span><span lang="EN-US">exec "$PRGDIR"/"$EXECUTABLE" start "$@" </span><span lang="ZH">中的</span><span lang="EN-US">start</span><span lang="ZH">改成</span><span lang="EN-US">jpda start</span><span lang="ZH">。由于默认的端口是</span><span lang="EN-US">8000</span><span lang="ZH">,所以如果</span><span lang="EN-US">8000</span><span lang="ZH">端口已有他用的话,还需在</span><span lang="EN-US">catalina.sh</span><span lang="ZH">文件中设置:</span><span lang="EN-US">JPDA_ADDRESS=8787</span><span lang="ZH">。</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="ZH">输入命令</span><span lang="EN-US">startup.sh</span><span lang="ZH">或者</span><span lang="EN-US">catalina.sh jpda start</span><span lang="ZH">就可启动</span><span lang="EN-US">tomcat</span><span lang="ZH">。</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="ZH">第二步、配置</span><span lang="EN-US">eclipse</span></p>
<p class="MsoNormal"><span lang="ZH">在</span><span lang="EN-US">Eclipse</span><span lang="ZH">中选择</span><span lang="EN-US">RunàDebug</span><span lang="ZH">,在弹出的对话框中右击</span><span lang="EN-US">Remote Java Application</span><span lang="ZH">新建一个远程调试项,如下如所示:</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="ZH">在</span><span lang="EN-US">“Name”</span><span lang="ZH">输入框中输入远程调试的名称,在</span><span lang="EN-US">“Project”</span><span lang="ZH">中选择要调试的项目,在</span><span lang="EN-US">“Host”</span><span lang="ZH">中输入需要远程调试项目的</span><span lang="EN-US">IP</span><span lang="ZH">,也就是</span><span lang="EN-US">tomcat</span><span lang="ZH">所在的</span><span lang="EN-US">IP</span><span lang="ZH">,在</span><span lang="EN-US">“Port”</span><span lang="ZH">中输入设置的端口号,比如上面设置的</span><span lang="EN-US">8787</span><span lang="ZH">,然后钩选</span><span lang="EN-US">“Allow termination of remote VM”</span><span lang="ZH">,点击</span><span lang="EN-US">“Apply”</span><span lang="ZH">即可。</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="ZH">设置完后就可以开始调试了,大概分一下几步:</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US">1</span><span lang="ZH">、</span><span lang="EN-US"> </span><span lang="ZH">启动</span><span lang="EN-US">tomcat</span><span lang="ZH">(远程),如在控制台输出</span><span lang="EN-US">“Listening
for transport dt_socket at address: 8787”</span><span lang="ZH">,即说明在</span><span lang="EN-US">tomcat</span><span lang="ZH">中设置成功;</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US">2</span><span lang="ZH">、</span><span lang="EN-US"> </span><span lang="ZH">在本机设置断点,即在需要监视的代码行前双击就会出现一个小圆点;</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US">3</span><span lang="ZH">、</span><span lang="EN-US"> </span><span lang="ZH">进入上图界面,选择要调试的项,点击</span><span lang="EN-US">“Debug”</span><span lang="ZH">即可进行远程调试;</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US">4</span><span lang="ZH">、</span><span lang="EN-US"> </span><span lang="ZH">当运行到设置了断点的代码行处即可看到如下图所示的浅绿条。</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="ZH">按键操作:</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US">1</span><span lang="ZH">、</span><span lang="EN-US">F5</span><span lang="ZH">键与</span><span lang="EN-US">F6</span><span lang="ZH">键均为单步调试,</span><span lang="EN-US">F5</span><span lang="ZH">是进入本行代码中执行,</span><span lang="EN-US">F6</span><span lang="ZH">是执行本行代码,跳到下一行;</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US">2</span><span lang="ZH">、</span><span lang="EN-US">F7</span><span lang="ZH">是跳出函数;</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US">3</span><span lang="ZH">、</span><span lang="EN-US">F8</span><span lang="ZH">是执行到最后。</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="ZH">当然,为了方便,可以新建一个批处理文件,假如取名为</span><span lang="EN-US">debug.bat</span><span lang="ZH">,在这个文件中加入下面几行:</span><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US">cd %CATALINE_HOME%/bin</span></p>
<p class="MsoNormal"><span lang="EN-US">set JPDA_ADDRESS=8787 </span></p>
<p class="MsoNormal"><span lang="EN-US">set JPDA_TRANSPORT=dt_socket</span></p>
<p class="MsoNormal"><span lang="EN-US">set CATALINA_OPTS=-server -Xdebug
-Xnoagent -Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787</span></p>
<p class="MsoNormal"><span lang="EN-US">startup</span></p>
<p class="MsoNormal"><span lang="EN-US"></span></p>

<p>
<span lang="ZH">这样需要远程调试时,运行</span><span lang="EN-US">debug.bat</span><span lang="ZH">即可;不需要远程调试时,还是运行</span><span lang="EN-US">startup.bat</span><span lang="ZH">文件。</span></p>
<p></p>
<p><span lang="ZH">本文来自baidu文档</span></p>

你可能感兴趣的:(tomcat)