emacs-lsp / lsp-java

lsp-mode :heart: java
https://emacs-lsp.github.io/lsp-java
GNU General Public License v3.0
647 stars 90 forks source link

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

Open LittleBlackTong opened 1 year ago

LittleBlackTong commented 1 year ago

(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

yyoncho commented 1 year ago

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)

LittleBlackTong commented 1 year ago

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?

yyoncho commented 1 year ago

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)

LittleBlackTong commented 1 year ago

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

yyoncho commented 1 year ago

can you check if these are vectors?

yyoncho commented 1 year ago

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

LittleBlackTong commented 1 year ago

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.

yyoncho commented 1 year ago

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.

LittleBlackTong commented 1 year ago

thaks it work!

mauricio-ms commented 1 year ago

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