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

lsp-java-configuration-runtimes And dap-java-java-command not warking

Open LittleBlackTong opened this issue 2 years ago • 10 comments

(use-package lsp-java :ensure t :init (setq lsp-java-java-path "/usr/local/Cellar/openjdk@17/17.0.7/libexec/openjdk.jdk/Contents/Home/bin/java") :config (setq lsp-java-configuration-runtimes '[(:name "JavaSE-1.8" :path "/usr/local/Cellar/openjdk@8/1.8.0+372/libexec/openjdk.jdk/Contents/Home/" :default t ) (:name "JavaSE-17" :path "/usr/local/Cellar/openjdk@17/17.0.7/libexec/openjdk.jdk/Contents/Home/" )]) (add-hook 'java-mode-hook 'lsp))

(require 'lsp-java-boot) ;; to enable the lenses (add-hook 'lsp-mode-hook #'lsp-lens-mode) (add-hook 'java-mode-hook #'lsp-java-boot-lens-mode)

(setq lsp-inhibit-message t) (setq lsp-ui-sideline-update-mode 'point)

(setq dap-java-java-command "/usr/local/Cellar/openjdk@8/1.8.0+372/libexec/openjdk.jdk/Contents/Home/bin/java") ;;(setq dap-java-java-command "/usr/local/Cellar/openjdk@17/17.0.7/libexec/openjdk.jdk/Contents/Home/bin/java")

(setq lsp-java-import-maven-enabled 1)

(setq lsp-java-configuration-maven-user-settings "/Users/zhou/Documents/DevelopTool/maven/settings.xml")

(setq lsp-java-vmargs '( "-XX:+UseParallelGC" "-XX:GCTimeRatio=4" "-XX:AdaptiveSizePolicyWeight=90" "-Dsun.zip.disableMemoryMapping=true" "-Xmx6G" "-Xms2G" "-javaagent:/Users/zhou/Documents/DevelopTool/maven/repository/org/projectlombok/lombok/1.18.26/lombok-1.18.26.jar" ))

this is my setting

I set dap-java-java-command to use 1.8 version of java but when I use dap-debug to debug the program it still uses 17 version of java

How to specify the java version when I debug the program with dap-debug

LittleBlackTong avatar Jul 11 '23 14:07 LittleBlackTong

That way of starting the application is performed by the jdtls, thus the server thinks that this project is 17. Check the .classpath in the root of the project. Alternativelly you may do M-x dap-debug and pick Java Run Configuration (compile/attach)

yyoncho avatar Jul 11 '23 17:07 yyoncho

I tried using Java Run Configuration (compile/attach) The 1.8 version is used to start this way, but the :env and :vmArgs I set did not take effect. How to solve this kind of question?

LittleBlackTong avatar Jul 12 '23 02:07 LittleBlackTong

You can register template with your settings. M-x dap-debug-edit-template (check which version you would want to use the one with C-u or not)

yyoncho avatar Jul 12 '23 05:07 yyoncho

(dap-register-debug-template "xxx-template" (list :type "java" :request "compile_attach" :vmArgs "-Denv=qa --add-opens java.base/java.lang=ALL-UNNAMED" :args "" :modulePaths (vector) :request "launch" :mainClass "com.weimob.rocket.xxx.xxx" :port 8080 :request "launch" :host "127.0.0.1" :env '(("WOAUTH_URL" . "xxx") ("APP_ID" . "rocket-xxx-xxx") ("HOSTNAME" . "qa") ("xxx" . "true")) ))

This is my template when I start with this template :env and :vmArgs have no effect

Is my template configuration wrong?

LittleBlackTong avatar Jul 12 '23 08:07 LittleBlackTong

can you check if these are vectors?

yyoncho avatar Jul 12 '23 09:07 yyoncho

-Denv=qa --add-opens java.base/java.lang=ALL-UNNAMED this can go in dap-java-java-command. vmArgs is used when the process is started by the language server.

yyoncho avatar Jul 12 '23 09:07 yyoncho

thanks thanks 🙏

How to set :env or :environment-variables when request is compile_attach?

i set :env '(("wlog.sdk.config.appLogSimpleTextFormat" . "true"))

It takes effect when the request is launch, but it will not take effect when the request is changed to compile_attach.

LittleBlackTong avatar Jul 12 '23 10:07 LittleBlackTong

Sounds like a bug. As a workaround you may set them in emacs like: (setenv "foo" "bar") and they will be used in child processes.

yyoncho avatar Jul 12 '23 10:07 yyoncho

thaks it work!

LittleBlackTong avatar Jul 12 '23 11:07 LittleBlackTong

I opened a PR to allow configure the vmArgs to be used by the dap-java-debug function.

Link: https://github.com/emacs-lsp/lsp-java/pull/450

mauricio-ms avatar Aug 26 '23 16:08 mauricio-ms