Repository navigation
Support for mvnDebug #49
Description
Activity
I think it's ok to use
mvnDebugvia settingmaven.executable.path. Most of time, the extension simply construct the commands, and sends to the integrated terminal. The exception is when generating effective pom, it usechild_process.execinstead.chriscamplejohn commented
on May 11, 2018 AuthorMore actionsI found that this doesn't work well as when you do things like compile it waits for a debugger to be connected. I wonder if a debug extension is needed to solve this properly?
Chris Camplejohn (@chriscamplejohn)
Yes, you're right.The feature should be provided in a new extension named as
Maven Debugger, using VS Code's debug protocol. (Documents HERE)I'm also interested in this feature.
dvirtz I'm also interested in the user experience you'd like to have. For the
mvnDebug jetty:runuse case which Chris Camplejohn (@chriscamplejohn) mentioned, actually there is a way of doing, following the steps.- set
"maven.executable.path": "mvnDebug". - execute some goals like
jetty:run, then it simply assemble the full commands and send to the terminal. Now it should wait for a debugger to be connected. (by default port 8000) - Create a Debug Configuration, choose "Java", or simply press F5, to generate a config:
{ "type": "java", "name": "Debug (Attach)", "request": "attach", "hostName": "localhost", "port": 8000 } - Choose this "attach" config and debug, if you have source code open in the workspace, it should work.
Please take a look whether this is the expected behavior.
Reacted by Murillo L do Carmo- set
chriscamplejohn commented
on Aug 28, 2018 AuthorMore actionsYan Zhang (@Eskibear) The issue I had when doing that is whenever you execute any maven operation it then waits for a debugger to connect which is a pain. You may as well do the manual step of starting the maven debug session in a shell and then connect with normal java debugging.
whenever you execute any maven operation it then waits for a debugger to connect which is a pain
Agree. But I'm just not sure whether we should put this feature in this extension, and how to implement. As you might know, currently this extension doesn't depend on any other extension. If you want it to start a debug session for you automatically, then we have to explicitly add "Debugger for Java" to dependencies. I'm not sure if it's a right thing to do.
A workaround for your issue
While we discuss about this, for your use case, you might have a try on "preLaunchTask". E.g.
.vscode/tasks.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "myMavenDebugCommand", "type": "shell", "command": "mvnDebug spring-boot:run", "group": "build" } ] }An "attach" config:
{ "type": "java", "name": "Debug (Attach)", "request": "attach", "hostName": "localhost", "port": 8008, "preLaunchTask": "myMavenDebugCommand" // <--It will be executed first. }Then all you need to do is running the "attach" config with F5.
chriscamplejohn commented
on Aug 28, 2018 AuthorMore actionsI will give this a go, but from memory the issue was that it was not reliable. The pre-task would execute, but after execution maven debug was not always started, it was only in the process of starting. This means that attach fails sometimes (sporadically). The difference between attach and debug is that attach only tries once where as debug waits for the process being debugged to become ready - so it will keep trying to attach.
Yan Zhang (@Eskibear) Can't you make an optional command which will be enabled only if
Debugger for Javais installed? Anyway, I don't believe there are many users which have this extension but not the debugger.Using
preLaunchTaskdoesn't work for me as it doesn't go pastListening for transport dt_socket at address: 8000Reacted by Pranithan- addedfeature-requestNew feature or requestNew feature or request
on Aug 29, 2018 dvirtz Do you set the right port 8000 in the "attach" config?
About the mvnDebug support, adding an optional command for mvnDebug to launch a debug session seems a little bit casual in design, and the maven extension actually has no knowledge of the listening port(if user has modified it).
Now I add "enhancement" label to mark it as a feature request. We can keep discussing in this thread.I did but it seems to wait for the task completion before entering debug.
If I try to run it in the background, like"command": "mvnDebug jetty:run &",the terminal is closed right after starting the task and the task terminates.
I just find a similar issue microsoft/vscode-java-debug#120
Thanks. I hope you'll raise the priority of this.
The suggestion Jinbo Wang (@testforstephen) made to click the debug button twice doesn't has no effect for me.testforstephen commented
on Aug 30, 2018 CollaboratorMore actionsIf the preLaunchTask points to a server mode or background task, you should use problemMatcher filter to tell VSCode it's ready. Then the Java debugger has the chance to attach to the mvnDebug port.
Below is the task.json spring-boot sample:
{ "label": "mvnDebug", "type": "shell", "command": "mvnDebug spring-boot:run", "isBackground": true, "problemMatcher": [{ "pattern": [{ "regexp": "\\b\\B", "file": 1, "location": 2, "message": 3 }], "background": { "activeOnStart": true, "beginsPattern": "^.*Preparing to execute Maven in debug mode.*", "endsPattern": "^.*Listening for transport dt_socket at address.*" } }] }And launch.json sample:
{ "type": "java", "name": "Debug (Attach)", "request": "attach", "hostName": "localhost", "port": "8000", "preLaunchTask": "mvnDebug" }Reacted by Chris Camplejohn, colwilson-mo, gaojx, allainmagyar, Victor Perez, Atli, Jon Boldt and Mohsin KhanReacted by Murillo L do Carmo and Jon Boldt- That works. Thanks!…On Thu, 30 Aug 2018 at 13:22, Jinbo Wang ***@***.***> wrote: If the preLaunchTask points to a server mode or background task, you should use problemMatcher filter to tell VSCode it's ready. Then the Java debugger has the chance to attach to the mvnDebug port. Below is the task.json spring-boot sample: { "label": "mvnDebug", "type": "shell", "command": "mvnDebug spring-boot:run", "isBackground": true, "problemMatcher": [{ "pattern": [{ "regexp": "\\b\\B", "file": 1, "location": 2, "message": 3 }], "background": { "activeOnStart": true, "beginsPattern": "^.*Preparing to execute Maven in debug mode.*", "endsPattern": "^.*Listening for transport dt_socket at address.*" } }] } And launch.json sample: { "type": "java", "name": "Debug (Attach)", "request": "attach", "hostName": "localhost", "port": "8000", "preLaunchTask": "mvnDebug" } — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#49 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AHTojYij5EVQbvcmKikd5J5KAlyssObkks5uV7zrgaJpZM4TqOfm> .
Since there's a workaround for it, I'm closing it. Currently, there's no feasible approach to provide such feature in this extension. Anyone who has a good solution please re-open it to continue the discussion.

Hi,
Is there any support for using mvnDebug instead of mvn? At present I have just added the following setting to use mvnDebug from my PATH.
"maven.executable.path": "mvnDebug"Not sure if there is a downside of this?
Use case is that I want to be able to use the jetty-maven-plugin and debug my servlet code. So I run mvnDebug jetty:run and then I can attach the vscode debugger.
Thanks
Chris