JARC
JARC

Reputation: 5328

How to run Jetty via Gradle in Debug Mode

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 to:

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

...but it doesn't seem to work.

I'm able to get my own jetty installation working fine, just not via gradle (jettyRun or jettyRunWar).

Regards.

Upvotes: 36

Views: 37201

Answers (9)

Luis Ramirez-Monterosa
Luis Ramirez-Monterosa

Reputation: 2242

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

Upvotes: 50

Damith Ganegoda
Damith Ganegoda

Reputation: 4328

add this into the build.gradle

jettyRun {
    jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'
}

Upvotes: 2

Cyrusmith
Cyrusmith

Reputation: 757

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.

Upvotes: 0

Sorokin Andrey
Sorokin Andrey

Reputation: 419

Also, please look at this two links from official wiki:

https://github.com/akhikhl/gretty/issues/36

http://akhikhl.github.io/gretty-doc/Debugger-support.html

It can help you to properly configurate gretty plugin to debug jetty application with IntelliJ Idea

Upvotes: 0

user3876447
user3876447

Reputation: 31

set GRADLE_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=n does NOT work for me too when run with gradle jettyRunWar.

I found another solution which works, run gradle jettyRunWar with below options gradle -Dorg.gradle.jvmargs="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" jettyRunWar.

But when I add the same parameter in gradle.properties, it doesn't work...

Upvotes: 3

akhikhl
akhikhl

Reputation: 2578

Try using Gretty plugin, it provided gradle tasks jettyRunDebug, jettyStartDebug etc.

Source code and doc: https://github.com/akhikhl/gretty

Disclosure: I am author of Gretty plugin.

Upvotes: 18

gongmingqm10
gongmingqm10

Reputation: 27

Im my cases, it doesn't work until I run the following command. GRADLE_OPTS='-XX:MaxPermSize=256M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4001' gradle jettyRun

And when it works, in the server console I can use System.out.println(...) to inspect what I want to see. As for breakpoint debug, unfortunately, I haven't find a way to it. Anyone knows how, welcome to add complement.

Upvotes: 0

user770119
user770119

Reputation: 442

Mine's a multi-project gradle build and I tried:

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

And that did NOT work. I even tried adding -Xnoagent to the GRADLE_OPTS setting above but that too did not make a difference. Also, setting JAVA_OPTS instead of GRADLE_OPTS did not solve the problem either. What solved the problem for me was adding a gradle.properties with:

org.gradle.jvmargs=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=5005,suspend=y

And immediately I could hit the breakpoint. May be solutions mentioned in other answers did not work for me because it is a multi-project build. Not sure!

Just wanted to provide the solution that worked for me in case above solutions do not work for other folks.

P.S: Tried with gradle 1.5/1.6 and adding the setting above to gradle.properties works for both versions!

Upvotes: 5

thoredge
thoredge

Reputation: 12591

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.

Upvotes: 6

Related Questions