Skip to content

Help needed: Can't find documentation to configure Java Attach to Process Debug  #340

Closed

Description

@me-heer

Did you check docs and existing issues?

  • I have read all the plugin docs
  • I have searched the existing issues
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.10.3

Operating system/version

MacOS 15.1.1

Describe the bug

I'm looking for an Attach to Process Configuration equivalent to the following VSCode Config:

"configurations": [
	{
		"type": "java",
		"name": "Debug Tomcat",
		"request": "attach",
		"hostName": "localhost",
		"port": "5005"
	},
]

But I can't find a way to configure it using nvim-java.

Here's my configuration (I have customized it starting from Kickstart): https://github.com/me-heer/nvim

Steps To Reproduce

  1. I have tried to add this: https://github.com/mfussenegger/nvim-dap/wiki/Java#configuration
  2. But executing :DapContinue does not show Attach to Process debug option

Expected Behavior

NA

Activity

  1. s1n7ax commented on Jan 7, 2025

    @s1n7ax
    Member

    This is automatically configured when you open a Java file. If you want custom configuration then you have to use dap APIs to do so. It's not in the scope of this project.

  2. s1n7ax commented on Jan 7, 2025

    @s1n7ax
    Member

    If what you are trying to say is that debug is not working out of the box, then i could look into it

  3. me-heer commented on Jan 7, 2025

    @me-heer
    Author

    If attach to process configuration is automatically configured, how do I invoke it?

    :DapContinue only shows classes which have main method in them, and there's no debug configuration of attaching to a process

  4. TheLeoP commented on Jan 8, 2025

    @TheLeoP
    Contributor

    This is automatically configured when you open a Java file. If you want custom configuration then you have to use dap APIs to do so. It's not in the scope of this project.

    The problem is that this plugin is overriding completely require'dap'.configurations.java on LspAttach, so it doens't matter if users are creating custom configurations, this plugin overrides them.

    To fix this, instead of setting require'dap'.configurations.java directly

    nvim_dap.configurations.java = dap_config

    a better approach would be to

    local dap = require'dap'
    dap.configurations.java = dap.configurations.java or {} -- define the array of configurations only if not previously defined
    
    -- do this in a for loop for each discovered configuration
    table.insert(dap.configurations.java, {
    -- some discovered configuration
    })
  5. s1n7ax commented on Jan 8, 2025

    @s1n7ax
    Member

    I would happily accept this PR

  6. me-heer commented on Jan 10, 2025

    @me-heer
    Author

    Thanks for the help.

    I have updated the plugin, and now my custom configuration (Attach to process) shows up in the :DapContinue options.

    However, when I execute it, I get the following error:

    Error executing vim.schedule lua callback: ...e/nvim/lazy/nvim-java-core/lua/java-core/utils/async.lua:41: unhandled error ...share/nvim/lazy
    /nvim-java-dap/lua/java-dap/api/setup.lua:50: To enrich the config, mainClass should already be present
    stack traceback:
            [C]: in function 'error'
            ...e/nvim/lazy/nvim-java-core/lua/java-core/utils/async.lua:41: in function 'callback'
            ...nvim-java-core/lua/java-core/ls/clients/jdtls-client.lua:72: in function 'handler'
            .../neovim/0.10.3/share/nvim/runtime/lua/vim/lsp/client.lua:687: in function ''
            vim/_editor.lua: in function <vim/_editor.lua:0>
    

    I have gone through the Trobleshooting section and applied this: https://github.com/nvim-java/nvim-java/wiki/Troubleshooting#no_entry-to-enrich-the-config-xxx-should-already-be-present

    My configuration for reference: https://github.com/me-heer/nvim/blob/master/init.lua#L1056-L1065

  7. TheLeoP commented on Jan 10, 2025

    @TheLeoP
    Contributor

    nvim-jdtls (the other java plugin for nvim from the same creator of nvim-dap) seems to discover the main clases during enrich_dap_config instead of before, like nvim-java (which is throwing an error because it expects those fields to be there). I don't know enough about how the java debug adapter works to help here, but nvim-jdtls has always worked for me, so I guess nvim-java-dap has to be modified to do the discovering of main classes later (?)

  8. me-heer commented on Jan 10, 2025

    @me-heer
    Author

    I don't know if this helps, but the directory I am opening has multiple Java projects in the subdirectories.

    Also, I don't understand why there needs to be a main class (or class with a main method) altogether since I am going to use "Attach to Debug" in a Spring MVC project where there's no custom class with a main method.

  9. agraven commented on Jun 16, 2025

    @agraven

    As a workaround adding the mainClass field to the debug configuration by hand will resolve this. The value should be the fully qualified reference to the main class, e.g. com.organization.foo.FooApplication.

  10. me-heer commented on Jun 18, 2025

    @me-heer
    Author

    Thanks for the suggestion, I appreaciate it. I use Spring MVC, so there's no main class, rather it's deployed on a web server like Tomcat and then we "Attach" to Debug

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions