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

后端 未结 4 724
失恋的感觉
失恋的感觉 2020-12-08 17:02

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

相关标签:
4条回答
  • 2020-12-08 17:37

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

    0 讨论(0)
  • 2020-12-08 17:44

    A better way of adding the debugging options to $MAVEN_OPTS option, and thus not merging them with the other existing options (if you want to start your app not in the debug mode, you have to remove those options again), is to use the Maven out of the box debugger mvnDebug, located in its bin directory, this way mvnDebug jetty:run. This will execute your app in debug mode and what's remaining is attaching your debugger.

    0 讨论(0)
  • 2020-12-08 17:50

    If you run your WAR with tomcat/jetty plugin pass debug options to the Maven:

    export MAVEN_OPTS="-Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" mvn tomcat:run
    

    If you run your WAR using the regular Tomcat, just run it with JPDA (debugger) support enabled:

    $TOMCAT_HOME/bin/catalina.sh jpda start
    

    Default port for Tomcat 6 JPDA is 8000.

    Now connect with the Eclipse (Debug -> Remote Java Application) to the port 8000 and enjoy your fine debugging session.

    0 讨论(0)
  • 2020-12-08 17:56

    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?

    With m2eclipse (and the Maven Integration for WTP that you install from the Extras), you could use the WTP and start your app in debug mode.

    As an alternative, you could connect a remote debugger to a Jetty. See Debugging with the Maven Jetty Plugin in Eclipse.

    0 讨论(0)
提交回复
热议问题