Skip to content

Support for mvnDebug #49

Description

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

Activity

  1. Eskibear commented on May 3, 2018

    @Eskibear
    Member

    I think it's ok to use mvnDebug via setting maven.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 use child_process.exec instead.

  2. chriscamplejohn commented on May 11, 2018

    @chriscamplejohn
    Author

    I 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?

  3. Eskibear commented on May 16, 2018

    @Eskibear
    Member

    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)

    And there would be an entry Maven in the following list:
    image

  4. dvirtz commented on Aug 28, 2018

    @dvirtz

    I'm also interested in this feature.

  5. Eskibear commented on Aug 28, 2018

    @Eskibear
    Member

    dvirtz I'm also interested in the user experience you'd like to have. For the mvnDebug jetty:run use case which Chris Camplejohn (@chriscamplejohn) mentioned, actually there is a way of doing, following the steps.

    1. set "maven.executable.path": "mvnDebug".
    2. 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)
    3. 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
          }
    4. 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.

  6. chriscamplejohn commented on Aug 28, 2018

    @chriscamplejohn
    Author

    Yan 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.

  7. Eskibear commented on Aug 28, 2018

    @Eskibear
    Member

    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.

  8. chriscamplejohn commented on Aug 28, 2018

    @chriscamplejohn
    Author

    I 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.

  9. dvirtz commented on Aug 29, 2018

    @dvirtz

    Yan Zhang (@Eskibear) Can't you make an optional command which will be enabled only if Debugger for Java is installed? Anyway, I don't believe there are many users which have this extension but not the debugger.

    Using preLaunchTask doesn't work for me as it doesn't go past

    Listening for transport dt_socket at address: 8000
    
  10. Eskibear commented on Aug 29, 2018

    @Eskibear
    Member

    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.

  11. dvirtz commented on Aug 29, 2018

    @dvirtz

    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.

  12. Eskibear commented on Aug 30, 2018

    @Eskibear
    Member

    I just find a similar issue microsoft/vscode-java-debug#120

  13. dvirtz commented on Aug 30, 2018

    @dvirtz

    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.

  14. testforstephen commented on Aug 30, 2018

    @testforstephen
    Collaborator

    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"
        }
    
  15. dvirtz commented on Aug 30, 2018

    @dvirtz
  16. Eskibear commented on Oct 12, 2018

    @Eskibear
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions