Java 如何使用eclipse调试JSP tomcat服务?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/67810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 07:53:15  来源:igfitidea点击:

How to debug a JSP tomcat service using eclipse?

javaeclipsetomcatdebugging

提问by user10402

I would like to debug my separately running JSP/Struts/Tomcat/Hibernate application stack using the Eclipse IDE debugger. How do I setup the java JVM and eclipse so that I can set breakpoints, monitor variable values, and see the code that is currently executing?

我想使用 Eclipse IDE 调试器调试我单独运行的 JSP/Struts/Tomcat/Hibernate 应用程序堆栈。如何设置 java JVM 和 eclipse 以便我可以设置断点、监视变量值并查看当前正在执行的代码?

回答by DustinB

I just Googled it. :)

我刚刚谷歌了一下。:)

http://bugs.sakaiproject.org/confluence/display/BOOT/Setting+Up+Tomcat+For+Remote+Debugging

http://bugs.sakaiproject.org/confluence/display/BOOT/Setting+Up+Tomcat+For+Remote+Debugging

Many more on google.

谷歌上还有更多。

Effectively, set your JPDA settings: set JPDA_ADDRESS=8000 set JPDA_TRANSPORT=dt_socket bin/catalina.bat jpda start

有效地设置您的 JPDA 设置: set JPDA_ADDRESS=8000 set JPDA_TRANSPORT=dt_socket bin/catalina.bat jpda start

Then, in Eclipse, Run->Debug Configurations...->Remote Applications.

然后,在 Eclipse 中,运行->调试配置...->远程应用程序。

回答by Dónal

Follow these steps:

按着这些次序:

  1. Add the following arguments to the javacommand that is used to launch Tomcat (on Windows, I think this is in TOMCAT\bin\catalina.bat)

    -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

  2. In Eclipse, create a 'Remote Java Application' debug configuration and set the port to 8787 and the host to the name (or IP address) of the machine where Tomcat is running. If Tomcat is running on the same machine as Eclipse, use 'localhost'.

  3. In the 'source' tab of the debug configuration, add any projects that you want to debug into

  4. Start Tomcat

  5. Launch the debug configuration you created in step 2

  6. Eclipse should now stop at any breakpoints that you've set in the projects you added in step 3.

  1. 将以下参数添加到java用于启动 Tomcat的命令中(在 Windows 上,我认为这是在 TOMCAT\bin\catalina.bat 中)

    -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

  2. 在 Eclipse 中,创建“远程 Java 应用程序”调试配置并将端口设置为 8787,将主机设置为运行 Tomcat 的机器的名称(或 IP 地址)。如果 Tomcat 与 Eclipse 运行在同一台机器上,请使用“localhost”。

  3. 在调试配置的“源”选项卡中,添加要调试的任何项目

  4. 启动Tomcat

  5. 启动您在第 2 步中创建的调试配置

  6. Eclipse 现在应该在您在步骤 3 中添加的项目中设置的任何断点处停止。

Notes:

笔记:

  • You can change the port to any other available port if for some reason you can't use 8787
  • If you want Tomcat to wait for the remote debugger to start, use 'suspend=n' in the command above to 'suspend=y'
  • 如果由于某种原因您不能使用 8787,您可以将端口更改为任何其他可用端口
  • 如果想让 Tomcat 等待远程调试器启动,请在上面的命令中使用 'suspend=n' 来 'suspend=y'

回答by MetroidFan2002

You could do what they suggest, or use this Eclipse plugin, which makes it easier to configure Tomcat to begin with: Eclipse Tomcat Plugin

你可以按照他们的建议去做,或者使用这个 Eclipse 插件,这使得配置 Tomcat 开始变得更容易:Eclipse Tomcat Plugin

When launching tomcat via this plugin, it starts in debug mode by default, you must explicitly disable debugging mode if you want it to not allow Eclipse to connect a remote debugger.

当通过这个插件启动 tomcat 时,它默认以调试模式启动,如果你想让它不允许 Eclipse 连接远程调试器,你必须明确禁用调试模式。

回答by Jeremy Stein

For Tomcat 5.5 on Windows:

对于 Windows 上的 Tomcat 5.5:

Edit bin/startup.bat

编辑 bin/startup.bat

Find the line that reads:

找到这样一行:

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

Replace it with these lines:

用这些行替换它:

set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%