reddit / emacs

Dap-java UnsupportedClassVersionError/Preview features error

FluentFelicity · 2022-02-02 21:50
Hi, all! Quick description of what's going on: I use LSP and am learning Java right now. Am trying lsp-java (which brings dap-java). LSP works fine with the jdtls server. However, when running any flavor of `dab-debug` in any Java project I get the following: ``` Error: LinkageError occurred while loading main class sol.TestRunner java.lang.UnsupportedClassVersionError: Preview features are not enabled for sol/TestRunner (class file version 61.65535). Try running with '--enable-preview' ``` I've changed `lsp-java-java-path` and `dap-java-java-command` to another version Java and added the "--enable-preview" argument to `lsp-java-vmargs` and `dap-java-args` to no avail. As far as I can tell everything related to java is updated to the latest version. Any tips for troubleshooting? SOLVED: The problem was in `dap-java` rather than `lsp-java`, which makes sense since this was only an issue that occurred when trying to debug. I had to add and set a `:vmArgs` keyword to the dap templates. It was tricky since this keyword is not in the default templates. It looks something like this: ``` ;; Copy and pasted from ~/main-emacs/straight/repos/lsp-java/dap-java.el (dap-register-debug-template "Java Run Configuration" (list :type "java" :request "launch" :vmArgs "--enable-preview" ; Needed :args "" :cwd nil :stopOnEntry :json-false :host "localhost" :request "launch" :modulePaths (vector) :classPaths nil :projectName nil :mainClass nil)) ```
yyoncho · 2022-02-03 19:47
what is the java version that you are using for dap-java-java-command and lsp equivalent? What command exactly do you use for running the debug build, M-x dap-debug? JFYI there is `dap-java-debug`.
FluentFelicity · 2022-02-03 23:07
I've tried everything with the defaults (unchanged). I am using JDK 17. What do you mean by "What command exactly do you use for running the debug build"? I've been using the default "Java Configuration" debug option from `dap-debug`/`dap-java-debug`. I've also tried using a dab template with "--enable-preview" in the `:args` line of the template. I will note that using the same JDK version on the same project in something like IntelliJ works. It's something in Emacs' side that doesn't.
King_Crank · 2022-02-25 03:18
Did you ever figure this out? I have the same issue.
FluentFelicity · 2022-02-25 03:21
Yep, I figured it out. Check out the solution I edited into the post.
King_Crank · 2022-02-25 03:50
Oh great didn't even see that part. I was using attach/compile instead of run. Thanks!