Skip to content

How to attach debug maven console applications

Andy Xu(devdiv) edited this page Mar 30, 2018 · 2 revisions

I will take maven quickstart project as example:

  • step 1. create the simple-app project, open a terminal and type: mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart then input the groupId and artifactId:

image

  • step 2: open the generated folder simple-app in vscode, wait for the startup of java extensions:

image

  • step 3: set a breakpoint at App.java and F5, choose java, a new folder named .vscode should be created

image

  • step 4: in terminal, goto the simple-app folder and type mvn package to build the maven project and then type mvnDebug exec:java -Dexec.mainClass="com.ms.samples.App" to start the mvn debug: (be careful about the package name, it should be the groupId you have inputted in step 1) image

  • step 5: back to vscode, modify the launch.json inside the .vscode folder and change the port to 8000 (the default debug port in maven), switch to debug view, change the debug configuration to "Debug (Attach)", and press F5 to start debug, wait some time and you will see the breakpoint is hit.

{
    "type": "java",
    "name": "Debug (Attach)",
    "request": "attach",
    "hostName": "localhost",
    "port": 8000
}

image

image

image

Clone this wiki locally