我无法使用Gradle,Dropwizard和IntelliJ调试JavaEE应用程序

问题描述 投票:1回答:1

我有一个带有Gradle的JavaEE应用程序,我在官方文档(对于Maven)和Gradle的另一个指南中添加了Dropwizard:

https://www.dropwizard.io/1.3.5/docs/getting-started.html https://karollotkowski.wordpress.com/2015/10/13/run-dropwizard-with-gradle/

该应用程序配置良好,使用Gradle和Dropwizard运行,但我想使用断点调试应用程序,我无法做到这一点。我按照本指南操作:

https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b

它看起来不错,因为当我运行命令时:

sudo ./gradlew run -Dorg.gradle.debug = true --no-daemon

Gradle等待我在IntelliJ中点击远程调试配置(我创建它)来运行应用程序,所以它应该没问题。但是,它在我的断点中永远不会停止(看起来它会忽略它们)。任何的想法?我分享了我认为重要的文件:

的build.gradle:

apply plugin: 'com.google.protobuf'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'

project.ext {
    dropwizardVersion = '1.3.0'
    configPath = "$rootProject.projectDir/config/"
}

//
// Loads of repositories and dependencies including dropwizard
//

protobuf {
// Configure the protoc executable
    protoc {
        // Download from repositories
        artifact = 'com.google.protobuf:protoc:3.0.0'
    }

    generateProtoTasks.generatedFilesBaseDir = 'generated'

    generateProtoTasks {
        // all() returns the collection of all protoc tasks
        all().each { task ->
            // Here you can configure the task
        }

        // In addition to all(), you may get the task collection by various
        // criteria:

        // (Java only) returns tasks for a sourceSet
        ofSourceSet('main')

    }
}

mainClassName = "com.company.MyApplication"

run {
    args 'server', configPath + ‘myapplication_config.yml'
}

shadowJar {
    mergeServiceFiles()
    exclude 'META-INF/*.DSA'
    exclude 'META-INF/*.RSA'
}

jar {
    manifest {
        attributes 'Main-Class': mainClassName
    }
}

build.dependsOn shadowJar

MyApplicationApplication(Dropwizard应用程序):

public class MyApplicationApplication extends Application<MyApplicationConfiguration> {

    public static void main(String[] args) throws Exception {

        new MyApplicationApplication().run(args);
    }

    @Override
    public void run(MyApplicationConfiguration configuration,
                    Environment environment) {

        environment.jersey().register(new RESTUserBilling());

    }
}

MyApplicationConfiguration(Dropwizard配置):

public class MyApplicationConfiguration extends Configuration {

}

myapplication_config.yml:

# Logging settings.
logging:

  # The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
  level: ERROR, DEBUG

  # Logger-specific levels.
  loggers:

    # Sets the level for 'com.example.app' to DEBUG.
    com.company: DEBUG

  appenders:
  - type: console
  - type: file
    threshold: INFO
    logFormat: "%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n"
    currentLogFilename: /var/log/dropwizard/myapplication.log
    archivedLogFilenamePattern: /var/log/dropwizard/myapplication-%d{yyyy-MM-dd}-%i.log.gz
    archivedFileCount: 7
    timeZone: UTC
    maxFileSize: 10MB

server:
  applicationContextPath: /myapplication
  adminConnectors:
  -
    port: 8091
    type: http
  applicationConnectors:
  -
    port: 80
    type: http

IntelliJ IntelliJ 2018.2.1(社区版)中的远程配置

enter image description here

Gradle 2.12

Java版本1.8.0_181

Dropwizard版本1.3.0

java gradle intellij-idea dropwizard
1个回答
1
投票

通过在该文章中使用-Dorg.gradle.debug=true,您正在调试Gradle的进程而不是您正在处理的应用程序。 Gradle在不同的进程中运行您的应用程序。你应该尝试gradle --debug-jvm run。阅读更多关于herehere的信息

并认真更新Gradle。 2.12太旧了。使用wrapper

如果2.12不理解--debug-jvm(可能是这种情况),那么只需找到一种方法来提供这样的字符串 - -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 - 到您的应用程序运行的JVM(而不是Gradle本身)。

© www.soinside.com 2019 - 2024. All rights reserved.