Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for mvnDebug #49

Closed
chriscamplejohn opened this issue Apr 27, 2018 · 16 comments
Closed

Support for mvnDebug #49

chriscamplejohn opened this issue Apr 27, 2018 · 16 comments
Assignees
Labels
discussion feature-request New feature or request

Comments

@chriscamplejohn
Copy link

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

@Eskibear
Copy link
Member

Eskibear commented May 3, 2018

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.

@chriscamplejohn
Copy link
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?

@Eskibear Eskibear self-assigned this May 12, 2018
@Eskibear
Copy link
Member

@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

@dvirtz
Copy link

dvirtz commented Aug 28, 2018

I'm also interested in this feature.

@Eskibear
Copy link
Member

@dvirtz I'm also interested in the user experience you'd like to have. For the mvnDebug jetty:run use case which @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.

@chriscamplejohn
Copy link
Author

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

@Eskibear
Copy link
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.

@chriscamplejohn
Copy link
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.

@dvirtz
Copy link

dvirtz commented Aug 29, 2018

@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

@Eskibear Eskibear added the feature-request New feature or request label Aug 29, 2018
@Eskibear
Copy link
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.

@dvirtz
Copy link

dvirtz commented Aug 29, 2018

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.

@Eskibear
Copy link
Member

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

@dvirtz
Copy link

dvirtz commented Aug 30, 2018

Thanks. I hope you'll raise the priority of this.
The suggestion @testforstephen made to click the debug button twice doesn't has no effect for me.

@testforstephen
Copy link
Contributor

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"
    }

@dvirtz
Copy link

dvirtz commented Aug 30, 2018 via email

@Eskibear
Copy link
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
Labels
discussion feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants