如何在 Eclipse 中调试在 jetty 上运行的 Web 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9066733/
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
How do i debug a web application running on jetty in eclipse?
提问by ollo
never done web programming before. Is there a way to set breakpoints, see variable values in eclipse? The app i want to debug makes a Query string whcih i would like to easily extract.
以前从未做过网络编程。有没有办法设置断点,看eclipse中的变量值?我要调试的应用程序生成了一个我想轻松提取的查询字符串。
回答by Usman Ismail
Click External Tools Config,
单击外部工具配置,
Select program and click the new button top left.
Set location to your maven binary
working directory to local workspace and arguments to jetty:run
选择程序并单击左上角的新按钮。将 Maven 二进制工作目录的位置设置为本地工作区并将参数设置为 jetty:run
In the environment tab set the maven opts. Notice socket address = 4000 and suspend=y
在环境选项卡中设置 maven opts。注意套接字地址 = 4000 和 suspend=y
The go to debug configurations and add a new remote application. Add a project name and set the socket address. Now run the External tool it should say:
转到调试配置并添加新的远程应用程序。添加项目名称并设置套接字地址。现在运行外部工具它应该说:
Listening for transport dt_socket at address: 4000
侦听地址为 4000 的传输 dt_socket
Then you can debug the remote app and add breakpoints etc.
然后你可以调试远程应用程序并添加断点等。
回答by eaykin
I would run the application with maven using the command: mvnDebug jetty:run
我会使用 maven 使用以下命令运行应用程序: mvnDebug jetty:run
And setup a remote Java application using port 8000, in Eclipse IDE.
并在 Eclipse IDE 中使用端口 8000 设置远程 Java 应用程序。
See the 'Setting up Maven 2.0.8+' section of: http://docs.codehaus.org/display/MAVENUSER/Dealing+with+Eclipse-based+IDE
请参阅“设置 Maven 2.0.8+”部分:http: //docs.codehaus.org/display/MAVENUSER/Dealing+with+Eclipse-based+IDE
回答by Shivan Dragon
None of the answers worked for me. Here's what did work:
没有一个答案对我有用。这是有效的:
- Create Maven Eclipse Runtime for your project:
- right-click on project -> maven build -> goals: jetty:run
- go to JRE tab of your Maven Eclipse Runtime, and in the VM arguments section add:
- 为您的项目创建 Maven Eclipse 运行时:
- 右键单击项目 -> maven build -> 目标:jetty:run
- 转到 Maven Eclipse 运行时的 JRE 选项卡,并在 VM 参数部分添加:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
When you execute this runtime, the first thing the Eclipse console outputs (in blue) is:
当您执行这个运行时,Eclipse 控制台输出的第一件事(蓝色)是:
Listening for transport dt_socket at address: 8000
侦听地址为 8000 的传输 dt_socket
Now you can create a Remote Java application Debug Runtime and connect to the debug port (8000 in this example)
现在您可以创建一个远程 Java 应用程序调试运行时并连接到调试端口(在本例中为 8000)
回答by Sumon Rahman
I would just expand eaykin's answer as the URL is broken.
由于 URL 已损坏,我只会扩展 eaykin 的答案。
Run the Mvn Debug as bellow...
运行 Mvn 调试如下...
$ mvnDebug -Dmaven.test.skip -Denvironment=dev clean jetty:run
$ mvnDebug -Dmaven.test.skip -Denvironment=dev clean jetty:run
This will wait on port 8000
这将在端口 8000 上等待
Preparing to Execute Maven in Debug Mode Listening for transport dt_socket at address: 8000
准备在调试模式下执行 Maven 侦听地址:8000 处的传输 dt_socket
Then go to the Eclipse Run --> Debug Configurations --> Remote Java Applications Define Host as 'localhost' and port as 8000 if they are not default.
然后转到 Eclipse 运行 --> 调试配置 --> 远程 Java 应用程序将主机定义为 'localhost',端口为 8000(如果它们不是默认值)。
If you click on the "Debug" button, this will start the application from mvn.
如果单击“调试”按钮,这将从 mvn 启动应用程序。
回答by Bhupendra
If by any chance you are using intellij. It is way easier. Make sure you have jetty plugin installed. Then
如果您有机会使用intellij。这要容易得多。确保安装了 jetty 插件。然后
- In the MavenTab on the extreme right, expand your project
- Expand Plugins
- Expand jetty
- Right click on jetty:runand select 'Debug DEBUG'Click to see the screenshot for refence
- 在最右侧的Maven选项卡中,展开您的项目
- 扩展插件
- 展开码头
- 右键单击jetty:run并选择'Debug DEBUG'点击查看截图以供参考
回答by zolee
"Trying to run it this way i get CreateProcess error=193, %1 is not a valid Win32 application."
“尝试以这种方式运行它时,我得到 CreateProcess 错误=193,%1 不是有效的 Win32 应用程序。”
On windows select mvn.bat instead of mvn.exe.
在 Windows 上选择 mvn.bat 而不是 mvn.exe。
回答by cyber-monk
The answer for this post shows you the flags need to pass to the JVM for a remote debugger to attach.
这篇文章的答案向您展示了需要传递给 JVM 以便远程调试器附加的标志。
Remote debug Jetty (no mvn, no plugins)
This is the page that explains remote debuggers for the JVM
这是解释 JVM 远程调试器的页面
http://docs.oracle.com/javase/1.3/docs/tooldocs/solaris/jdb.html
http://docs.oracle.com/javase/1.3/docs/tooldocs/solaris/jdb.html