Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to debug Java web application packaged as a WAR using Eclipse and Maven?

I've not built a Java web application before, but I have it complete enough to test and Maven is building my WAR file just fine. It is a multi-module Maven project and the dependent modules all have their JAR files in the WEB-INF/lib directory of the WAR.

So everything seems fine, but how to debug? I know how to (from the command line) run the WAR in Tomcat on my machine. I also think I know how to set up and run the Maven Jetty plugin from the command line as well. But how best to debug...with all the break points and variable inspection I love with Eclipse?

Is there some kind of launch configuration I should create, or do I attach the debugger remotely? Is there something in Eclipse that can help...like a plugin?

like image 728
HDave Avatar asked Sep 16 '10 04:09

HDave


People also ask

Can we debug maven project in Eclipse?

Using Eclipse to debug tests run with MavenOpen the Debug Configuration in Eclipse and set up a remote application on port 5005. Run the configuration. The test will resume. You can use break points and all the usual features of Eclipse debugging.

How do I create an executable war file in Eclipse project?

To create war file, you need to use jar tool of JDK. You need to use -c switch of jar, to create the war file. Go inside the project directory of your project (outside the WEB-INF), then write the following command: jar -cvf projectname.

Can we debug in Maven?

You can use the maven. surefire. debug property to debug your forked tests remotely, like this: mvn -Dmaven.


1 Answers

To enable debugging through eclipse :

I pass following to Tomcat startup:

-Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=9999,suspend=n

Then through Eclipse do Remote Debug.

  • Goto Debug Menu > Debug Configuration

  • Scroll Down to Select Remote Java Application

  • rt click to create new
    configuration
  • Select connection type as Standard (Socket Attach) and add hostname and port.

To start debugging simple open it when server is running.---

like image 70
YoK Avatar answered Sep 21 '22 01:09

YoK