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

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

Open
LittleBlackTong opened this issue Jul 11, 2023 · 10 comments

Comments

@LittleBlackTong
Copy link

(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
Copy link
Member

yyoncho commented Jul 11, 2023

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
Copy link
Author

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
Copy link
Member

yyoncho commented Jul 12, 2023

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
Copy link
Author

(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
Copy link
Member

yyoncho commented Jul 12, 2023

can you check if these are vectors?

@yyoncho
Copy link
Member

yyoncho commented Jul 12, 2023

-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
Copy link
Author

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
Copy link
Member

yyoncho commented Jul 12, 2023

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
Copy link
Author

thaks it work!

@mauricio-ms
Copy link
Contributor

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

Link: #450

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants