How to run Jetty via Gradle in Debug Mode

后端 未结 9 1461
醉话见心
醉话见心 2020-12-13 00:43

Does anyone know how to configure the jetty gradle plugin to run in debug mode so that I can attach a remote debugger?

I\'ve tried setting the gradle and java opts t

相关标签:
9条回答
  • 2020-12-13 00:59

    I ran it with org.gradle.debug property:

    ./gradlew -Dorg.gradle.debug=true jettyRun

    At this point gradle freezes and waits for incoming debug connections.

    Then I created Remote Run configuration in IntelliJ with value of "Command line arguments for running remote JVM" to be -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

    Finally, I ran this new configuration, gradle resumed progress and IDE stopped at the first breakpoint.

    0 讨论(0)
  • 2020-12-13 01:10

    Are you running gradle in daemon mode? As I understand it the daemon will then be running the jetty instance. Therefore you'll need to set the JVM args for the daemon. This should be possible by setting the org.gradle.jvmargs in gradle.properties.

    See http://gradle.org/docs/current/userguide/tutorial_this_and_that.html#sec:gradle_properties_and_system_properties

    Simply project that works here in non-daemon mode

    build.gradle:

    apply plugin: 'idea'
    apply plugin: 'jetty'
    

    src/main/java/com/Test.java:

    package com;
    public class Test {
        static public String greet() {
            return "Hi";
        }
    }
    

    src/main/webapp/index.jsp:

    <%@ page import="com.Test" %>
    <html><body>
    <%= Test.greet() %>
    </body></html>
    

    Command-line (in cygwin though):

    $ GRADLE_OPTS='-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=n' gradle jettyRun
    

    Gradle then hangs and I can put debugger from Intellij on port 9999 and set a breakpoint in the java file. When I then try to open the web page jetty informs me about I will hit the breakpoint.

    0 讨论(0)
  • 2020-12-13 01:11

    On Linux:

    export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=n"
    gradle jettyRun
    

    On Windows:

    set GRADLE_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=‌​n
    gradle jettyRun
    
    0 讨论(0)
提交回复
热议问题