How to debug java project compiled with ant in ecl

2019-08-17 12:54发布

问题:

I have a java website hosted in a debian VPS server.

When I write new code, I test the web app in my local machine, before to deploy it.

In the VPS server I have ant installed, so I always compile my code in the VPS server and then I put the generated WAR file in the webapp folder of tomcat installed in my local machine to test.

To compile the source code with ant I write the followings commands.

ant fetch-deps
ant

I need to debug my web app with eclipse. I'd like to have a debug configuration which:

  • compiles the web project witn ant, in the same way I do in the VPS server

  • deploys the generated war to a tomcat server (tomcat server inside
    eclipse should be fine)

  • opens a debug session, so that I can put break points in my code and debug my app line by line

I have serached in google, but I can't find a step by step tutorial for my case. I tried to configure my debug with pieces of information I found here and there in the web, but something goes wrong... so I need a step by step explanation.

I tried to activate debug in my local tomcat webserver, but break points were not hitted. It seems that in the debug session with tomcat, eclipse and tomcat are not able to correctly map the WAR file with the source code.

回答1:

Using Eclipse Oxygen with the new Launch group feature:

  • Build and deploy the war with ant. Deploy with ant explained here.
  • Create a remote debug configuration.
  • Create a Launch group configuration (Run configurations) and add the build and debug configurations to it.

PS: add a delay between launches to allow app to be deployed.