Debug java micronaut microservice in visual studio code

半腔热情 提交于 2021-01-28 11:01:38

问题


I created a microservice using micronaut and visual studio code. Everything is working find when I run the service using the gradlew.bat. I want to debug my microservice using visual studio code but annotation processing are not working.

When I debug the service in visual studio code, it runs the main class and starts listening the localhost port but none of my controllers is found This is my launch configuration:

{
    "type": "java",
    "name": "Debug (Launch)-Application<keycloak>",
    "request": "launch",
    "cwd": "${workspaceFolder}",
    "console": "internalConsole",
    "stopOnEntry": false,
    "mainClass": "com.test.Application",
    "args": "",
    "projectName": "keycloak"
}

This is my gradle file:

buildscript {
    repositories {
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "com.github.jengelman.gradle.plugins:shadow:2.0.4"
        classpath "io.spring.gradle:dependency-management-plugin:1.0.5.RELEASE"
        classpath "net.ltgt.gradle:gradle-apt-plugin:0.15"
    }
}

version "0.1"
group "com.test"
apply plugin:"io.spring.dependency-management"
apply plugin:"com.github.johnrengelman.shadow"
apply plugin:"application"
apply plugin:"java"
apply plugin:"net.ltgt.apt-eclipse"
apply plugin:"net.ltgt.apt-idea"
repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://jcenter.bintray.com" }
}
dependencyManagement {
    imports {
        mavenBom 'io.micronaut:bom:1.0.0.M4'
    }
}
dependencies {
    annotationProcessor "io.micronaut:inject-java"
    compile "io.micronaut:inject"
    compile "io.micronaut:runtime"
    compile "io.micronaut:http-client"
    compile "io.micronaut:http-server-netty"
    compile "be.looorent:keycloak-micronaut-adapter:1.3.0"
    compileOnly "io.micronaut:inject-java"
    runtime "ch.qos.logback:logback-classic:1.2.3"
    testCompile "junit:junit:4.12"
    testCompile "io.micronaut:inject-java"
}
shadowJar {
    mergeServiceFiles()
}
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1')
mainClassName = "com.test.Application"
compileJava.options.compilerArgs += '-parameters'
compileTestJava.options.compilerArgs += '-parameters'

Thanks in advance


回答1:


I don't know how you can debug your application directly in VSC but for sure you can run the service from the command line and then attach the process using the remote debug.

To do that follow the next steps:

  1. change your gradle file and use java remote debug change this line: run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1') to: run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1','-Xdebug',"-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n") (note the port 8000 in the jvm args)

  2. add this launch configuration

    { "type": "java", "name": "Debug (Attach)", "request": "attach", "hostName": "localhost", "port": 8000 -> here use the same port you use in the jvm arg }

  3. run your service as usual using gradlew from the command

  4. Go to VSC and then attach the process to port 8000 using the launch configuration in step 2


来源:https://stackoverflow.com/questions/52509794/debug-java-micronaut-microservice-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!