如何在Eclipse中调试WAR应用程序?

huangapple go评论96阅读模式
英文:

How to debug WAR application inside eclipse?

问题

I have seen many online tutorials explaining how to use Eclipse to do remote debugging of a WAR file.

But what I want to know is how to debug inside Eclipse, just like debugging a Java application. I have Tomcat 7 configured in my Eclipse as a server, and I have tested it with a sample servlet program successfully, which means I can set breakpoints in the source code and run into them.

My WAR application is built using Gradle. I have imported the Gradle project into my Eclipse and built it successfully within Eclipse by running Gradle tasks inside the "Gradle Tasks View." I added the project to the server. However, when I try to use "Debug as > Debug on Server," it fails, and the breakpoint is not hit. Can anyone share their experience debugging a WAR file inside Eclipse?

英文:

I have seen many online tutorial explaining how to use eclipse to do remote debug of WAR file.

But what I want to know is how to do the debug inside eclipse just as debugging a JAVA application? I have Tomcat 7 configured in my eclipse as a server. And I have tested it with a sample servlet program successfully meaning I can set breakpoint in the source code and run into it.

My WAR application is built by gradle. I have imported the gradle project into my eclipse and build it ok inside eclipse by running gradle task inside "gradle tasks view". I added the project into the server. However, when I try to use "Debug as > Debug on Server", it fails and the breakpoint is not get hit. Anyone could share the experience to debug WAR inside eclipse?

答案1

得分: 2

我是IntelliJ Idea用户,但我有一个通用建议。您可以运行您的应用程序(war/jar等)并打开调试端口,然后从eclipse使用远程调试(或连接到进程的选项)。

确保您拥有与创建war/jar的代码完全相同的副本,否则在调试时可能会出现代码行不匹配的情况,这将很难理解。

英文:

I am a IntelliJ Idea user but I have a generic advice here. What you can do is that you can run your application (war/jar etc) with debug port on and then from eclipse use remote debug (or attached to a process sort of option).

Make sure you have exact copy of the code from which you have created war/jar otherwise lines might mismatch while debugging and will be hard to make sense.

答案2

得分: 0

在"Servers"视图中,选择正确的Tomcat服务器概述,然后进入"Modules"选项卡。

在那里,您可以通过点击"Add External Web Module..."来添加WAR文件。

如何在Eclipse中调试WAR应用程序?

在"文档基础"中设置WAR文件路径,在"路径"字段中设置您想要的内容。

示例:

文档基础:"C:\eclipse-workspace\MyProject\war\myWarToDebug.war"

路径:"/myapp"

以调试模式启动服务器。使用以下URL访问您的应用程序
<yourServerHost>:<serverPort>/<pathSetInModuleTab>

请注意,当到达断点时,Eclipse可能会显示找不到源文件。只需进入服务器调试配置并在"Source"选项卡中添加项目源文件。

英文:

On the "Servers" view, select the right tomcat server overview, then go on the "Modules" tab.

There, you can add the war by clicking on "Add External Web Module...".

如何在Eclipse中调试WAR应用程序?

Set the war path in the "Document base", and what ever you want on the "Path" field.

Example:
>Document base: "C:\eclipse-workspace\MyProject\war\myWarToDebug.war"
>
>Path: "/myapp"

Start the server in debug mode. Access your app using the url
&lt;yourServerHost&gt;:&lt;serverPort&gt;/&lt;pathSetInModuleTab&gt;.

Note that when reaching the breakpoint, Eclipse may say there is no sources found. Simply go on the server debug configuration and add the project sources in the "Source" tab.

答案3

得分: -1

Before debug you must decompile using jd gui for open class file inside war file and save as java project.

英文:

Before debug you must decompile using jd gui for open class file inside war file and save as java project.

huangapple
  • 本文由 发表于 2020年8月13日 16:00:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63390657.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定