简体   繁体   中英

Debug java micronaut microservice in visual studio code

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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