1

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?

Max Li
  • 551
  • 2
  • 14
  • Same question already exists, You may refer to [this](https://stackoverflow.com/questions/3723743/best-way-to-debug-java-web-application-packaged-as-a-war-using-eclipse-and-maven) – ZA1NZAFAR Aug 13 '20 at 08:06
  • The link you provide is about remote debug, isn't it? In my question, I have specifically said that I want to know is there a way to debug WAR not in the "remote" way.... – Max Li Aug 13 '20 at 08:40
  • If you disagree with a close ... just contact the person who closed, by using the @ userid in a comment. I thought that the other answer ALSO included suggestions for "local" usage. – GhostCat Aug 13 '20 at 09:07

3 Answers3

2

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.

Saurav Kumar Singh
  • 1,352
  • 7
  • 18
0

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...".

image source: https://devtidbits.com/2011/10/07/embed-a-railo-coldfusioncfml-server-within-your-cfeclipseeclipse-application-with-no-need-for-xml-configurations/

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 <yourServerHost>:<serverPort>/<pathSetInModuleTab>.

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.

jhamon
  • 3,603
  • 4
  • 26
  • 37
  • right click on the server in server view, I don't see a menu item called "overview"? – Max Li Aug 13 '20 at 08:49
  • @MaxLi double-click on the server in the "Server" view – jhamon Aug 13 '20 at 09:10
  • I found it. I added the path of the WAR in. However, my WAR is a Spring Application. I started Tomcat in debug mode, from the console I don't see the normal Spring startup screen. Even after I type in the http://localhost:8080/XXXXX I see nothing happening in the console. So I guess Tomcat does not start my WAR at all? – Max Li Aug 13 '20 at 09:33
  • Eclipse does not allow selecting a war file that way, but it can be entered by manually typing the filename. Unfortunately, that didn't help me achieve my goal as Tomcat wouldn't properly start anyway. I gave up. – Philippe Cloutier Jan 23 '23 at 17:07
-1

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

  • 2
    If he has the gradle project, don't you think he already has the source? – jhamon Aug 13 '20 at 08:04
  • hmm.... could you elaborate the details of this approach? What does decompile mean?What is jd gui? I ever tried to use jar command to unpack WAR and was able to see all those class files. And how to save class files inside war file as java project? – Max Li Aug 13 '20 at 08:07
  • Your answer is based on assumptions. It would be an "okay" comment to ask the OP whether they configured their setup to have source code available. But it is definitely not worth writing up an "answer" for such a suggestion. – GhostCat Aug 13 '20 at 08:07
  • @MaxLi When you want to debug an application, the debugger (in your case: eclipse) needs access to the source code. But the advice given here is nonsensical. You should rather acquire the official source code packages for the components you are using. And when you are using a build system like gradle, you get that almost for free already. The idea of using a tool like jd to turn class files back into source code for this problem is plain ridiculous. – GhostCat Aug 13 '20 at 08:08