lsp-java icon indicating copy to clipboard operation
lsp-java copied to clipboard

dap-java-debug fails with unrecognized option -Xnoagent on JDK 22

Open my0811 opened this issue 7 months ago • 4 comments

Java HotSpot(TM) 64-Bit Server VM warning: Option -Xdebug was deprecated in JDK 22 and will likely be removed in a future release. Unrecognized option: -Xnoagent Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.

Image

It seems that -Xnoagent is no longer supported, and -Xdebug is deprecated in JDK 22. Could you update the debug configuration to be compatible with newer JDK versions?

Additionally, after running dap-java-debug, Emacs becomes completely unresponsive — all keybindings stop working and the editor freezes.

my0811 avatar Apr 06 '26 05:04 my0811

have you figured a solution?

iamziad avatar Sep 16 '26 23:09 iamziad

I recommend to switch to eglot and dape. I have been using them for years.

feiyuxsh-sketch avatar Sep 17 '26 00:09 feiyuxsh-sketch

eglot is great, but it doesn't work well with java, idk why, maybe it's better now, i'll give it another try.

iamziad avatar Sep 17 '26 08:09 iamziad

@iamziad I have to tell you that eglot works with java very well. I strongly recommend you give it a try. Here's my configuration you can just copy and modify it for you. I moved from lsp-java to eglot years ago, because of the slowness and debug error.

(with-eval-after-load 'eglot
  (add-to-list 'eglot-server-programs
               `(java-mode . ("/home/huang/jdtls/jdtls.1.57/bin/jdtls" :initializationOptions
                              (
                               :settings
                               (
                                :java
                                (
                                 :configuration (:runtimes [(:name "JavaSE-11" :path "/usr/local/jdk-17.0.13+11/" :sources "/usr/local/jdk-17.0.13+11/lib/src.zip" :default t)
                                                            (:name "JavaSE-21" :path "/usr/lib/jvm/java-21-openjdk-amd64")
                                                            ])
                                 :saveActions (:organizeImports t)
                                 :completion (
                                              :enabled t
                                              :overwrite t
                                              :guessMethodArguments t
                                              :importOrder ["java" "javax" "jakarta" "org.apache" "org.hibernate" "org.json" "org" "co" "com" "io" "net" "redis" "software" "com.etix" "com.intellimark" "test"])
                                 )
                                )
                               :extendedClientCapabilities (:classFileContentsSupport t)
                               :bundles ["/home/huang/.m2/repository/com/microsoft/java/com.microsoft.java.debug.plugin/0.53.1/com.microsoft.java.debug.plugin-0.53.1.jar"]
                               )
                              )))
  (define-key eglot-mode-map (kbd "s-l r r") 'eglot-rename)
  (define-key eglot-mode-map (kbd "s-l g h") (lambda () (interactive) (eglot-show-call-hierarchy 'incoming)))
  (define-key eglot-mode-map (kbd "s-l g i") 'eglot-find-implementation)
  (define-key eglot-mode-map (kbd "<M-return>") 'eglot-code-actions)
  ;; (add-hook 'eglot-mode-hook 'completion-preview-mode)
  )
(setq eglot-max-file-watches nil)

;; dape for debug
(use-package dape
  :ensure t
  :config
  ;; Info buffers to the right
  (setq dape-buffer-window-arrangement 'right)
  ;; Global bindings for setting breakpoints with mouse
  (dape-breakpoint-global-mode)
  )
;; for debug web application, you may not needed if the project is not a web application.
(add-to-list 'dape-configs
               `(java-attach
                 modes (java-mode)
                 fn (lambda (config)
                      (with-current-buffer
                          (find-file-noselect (expand-file-name (plist-get config :program)
                                                                (project-root (project-current))))
                          (thread-first
                            config
                            (plist-put 'hostname "localhost")
                            (plist-put 'port (eglot-execute-command (eglot-current-server)
                                                                    "vscode.java.startDebugSession" nil))
                            )))
                 :program dape-buffer-default
                 :projectName "web-online"
                 :type "java"
                 :request "attach"
                 :hostName "localhost"
                 :port 11550))

huangfeiyu avatar Sep 17 '26 09:09 huangfeiyu