简体   繁体   English

如何在调试模式下通过Gradle运行Jetty

[英]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? 有谁知道如何配置jetty gradle插件以在调试模式下运行,以便我可以附加远程调试器?

I've tried setting the gradle and java opts to: 我试过设置gradle和java选择:

-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). 我可以使自己的码头安装工作正常,而不必通过gradle(jettyRun或jettyRunWar)进行安装。

Regards. 问候。

On Linux: 在Linux上:

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

On Windows: 在Windows上:

set GRADLE_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=‌​n
gradle jettyRun

Try using Gretty plugin, it provided gradle tasks jettyRunDebug, jettyStartDebug etc. 尝试使用Gretty插件,它提供了gradle任务jettyRunDebug,jettyStartDebug等。

Source code and doc: https://github.com/akhikhl/gretty 源代码和文档: https : //github.com/akhikhl/gretty

Disclosure: I am author of Gretty plugin. 披露:我是Gretty插件的作者。

Are you running gradle in daemon mode? 您是否在守护程序模式下运行gradle? 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. 因此,您需要为守护程序设置JVM args。 This should be possible by setting the org.gradle.jvmargs in gradle.properties. 这可以通过在gradle.properties中设置org.gradle.jvmargs来实现。

See http://gradle.org/docs/current/userguide/tutorial_this_and_that.html#sec:gradle_properties_and_system_properties 参见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: build.gradle:

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

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

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

src/main/webapp/index.jsp: src / main / webapp / index.jsp:

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

Command-line (in cygwin though): 命令行(尽管在cygwin中):

$ 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. Gradle然后挂起,我可以将Intellij的调试器放在端口9999上,并在java文件中设置一个断点。 When I then try to open the web page jetty informs me about I will hit the breakpoint. 然后,当我尝试打开网页时,码头通知我即将到达断点。

Mine's a multi-project gradle build and I tried: 我的是一个多项目gradle构建,我尝试过:

$ 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. 我什至尝试将-Xnoagent添加到上面的GRADLE_OPTS设置中,但这也没有任何区别。 Also, setting JAVA_OPTS instead of GRADLE_OPTS did not solve the problem either. 同样,设置JAVA_OPTS而不是GRADLE_OPTS也不能解决问题。 What solved the problem for me was adding a gradle.properties with: 为我解决了问题的是添加了gradle.properties与:

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. 只是想提供适用于我的解决方案,以防上述解决方案不适用于其他人。

PS: Tried with gradle 1.5/1.6 and adding the setting above to gradle.properties works for both versions! PS:尝试过gradle 1.5 / 1.6,并将上面的设置添加到gradle.properties中,适用于两个版本!

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 . 当使用gradle jettyRunWar运行时, set GRADLE_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y,suspend=n对我也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 . 我找到了另一种有效的解决方案,运行gradle jettyRunWar并使用以下选项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... 但是当我在gradle.properties中添加相同的参数时,它不起作用...

add this into the build.gradle 将此添加到build.gradle

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

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. 并且当它起作用时,在服务器控制台中,我可以使用System.out.println(...)来检查我要查看的内容。 As for breakpoint debug, unfortunately, I haven't find a way to it. 至于断点调试,不幸的是,我还没有找到解决方法。 Anyone knows how, welcome to add complement. 谁都知道,欢迎补充。

Also, please look at this two links from official wiki: 另外,请查看官方Wiki中的以下两个链接:

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

http://akhikhl.github.io/gretty-doc/Debugger-support.html 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 它可以帮助您正确配置gretty插件以使用IntelliJ Idea调试码头应用程序

I ran it with org.gradle.debug property: 我使用org.gradle.debug属性运行它:

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

At this point gradle freezes and waits for incoming debug connections. 此时,gradle冻结,并等待传入​​的调试连接。

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 然后,我在IntelliJ中创建了远程运行配置,其值为“用于运行远程JVM的命令行参数”为-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. 最后,我运行了这个新配置,gradle恢复了进度,IDE在第一个断点处停止了运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM