emacs-lsp / lsp-java

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

jdtls-server will not start. #426

Open opensource-philosophy opened 1 year ago

opensource-philosophy commented 1 year ago

This problem seems closely related to #293.

When trying to start the lsp-java server, I receive the message

Server jdtls:27072/starting exited with status exit(check corresponding stderr buffer for detail). Do you want to restart it? (y or n)

When looking in the Messages buffer, I read

using config for config_linux
LSP :: Connected to [jdtls:34071/starting].
When done with a buffer, type C-x #
LSP :: jdtls has exited (exited abnormally with code 13)
Server jdtls:34071/starting exited with status exit(check corresponding stderr buffer for details). Do you want to restart it? (y or n) y

The stderr buffer reads

Process jdtls stderr finished

M-: lsp-java--ls-command results in

("/usr/lib/jvm/java-19-openjdk/bin/java" "-Declipse.application=org.eclipse.jdt.ls.core.id1" "-Dosgi.bundles.defaultStartLevel=4" "-Declipse.product=org.eclipse.jdt.ls.core.product" "-Dlog.protocol=true" "-Dlog.level=ALL" "-XX:+UseParallelGC" "-XX:GCTimeRatio=4" "-XX:AdaptiveSizePolicyWeight=90" "-Dsun.zip.disableMemoryMapping=true" "-Xmx1G" "-Xms100m" "-jar" "/home/user-name/.emacs.d/.cache/lsp/eclipse.jdt.ls/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar" "-configuration" "/home/user-name/.emacs.d/.cache/lsp/eclipse.jdt.ls/config_linux" "-data" "/home/user-name/.emacs.d/workspace/" "--add-modules=ALL-SYSTEM" "--add-opens java.base/java.util=ALL-UNNAMED" "--add-opens java.base/java.lang=ALL-UNNAMED")

Manually executing the code gives

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Content-Length: 122

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"26.03.2023, 13:55:15 Main thread is waiting"}}

I have multiple versions of Java installed, but the current version (found out by which java) is java-19-openjdk. I am using the code below to setup my Emacs for lsp-java.

  (use-package lsp-java
  :ensure t
  :config
  (add-hook 'java-mode-hook 'lsp)
  (setq lsp-java-completion-max-results 10)
  (setenv "JAVA_HOME"  "/usr/lib/jvm/java-19-openjdk/")
  (setq lsp-java-inhibit-message nil)
  (setq lsp-java-save-actions-organize-imports t)
  (setq lsp-java-java-path "/usr/lib/jvm/java-19-openjdk/bin/java")
  (setq lsp-java-configuration-runtimes '[(:name "JavaSE-19"
                                                 :path "/usr/lib/jvm/java-19-openjdk/"
                                                 :default t)]))

(use-package dap-mode
  :ensure t
  :after lsp-mode
  :config (dap-auto-configure-mode))

(use-package dap-java :ensure nil)

As you can see, I am already trying to make every path explicit. What I have also tried is …

  1. deleting the path of lsp-java-workspace-dir.
  2. Reinstalling the jdtls server.

What could be the problem?

yyoncho commented 1 year ago

can you do M-x lsp-toggle-trace-io and then look for the log buffer content?

opensource-philosophy commented 1 year ago

Thanks for the quick answer! Here is the log:

Found the following clients for/path/to/file.java: (server-id jdtls, priority 0)
The following clients were selected based on priority: (server-id jdtls, priority 0)
Found the following clients for/path/to/file.java: (server-id jdtls, priority 0)
The following clients were selected based on priority: (server-id jdtls, priority 0)
Found the following clients for/path/to/file.java: (server-id jdtls, priority 0)
The following clients were selected based on priority: (server-id jdtls, priority 0)
Found the following clients for/path/to/file.java: (server-id jdtls, priority 0)
The following clients were selected based on priority: (server-id jdtls, priority 0)
Found the following clients for/path/to/file.java: (server-id jdtls, priority 0)
The following clients were selected based on priority: (server-id jdtls, priority 0)
Found the following clients for/path/to/file.java: (server-id jdtls, priority 0)
The following clients were selected based on priority: (server-id jdtls, priority 0)
Found the following clients for/path/to/file.java: (server-id jdtls, priority 0)
The following clients were selected based on priority: (server-id jdtls, priority 0)
yyoncho commented 1 year ago

This is not the log we are looking for. It is named like this: *lsp-log: jdtls:108480*

opensource-philosophy commented 1 year ago

Sorry, there was a buffer lsp-log of which I copied the contents. This should be the correct log:

[Trace - 07:47:33 ] Sending request 'initialize - (7)'.
Params: {
  "processId": null,
  "rootPath": "/root/path",
  "clientInfo": {
    "name": "emacs",
    "version": "GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.36, cairo version 1.17.6)\n of 2023-01-03"
  },
  "rootUri": "file:///path/to/file/folder",
  "capabilities": {
    "workspace": {
      "workspaceEdit": {
        "documentChanges": true,
        "resourceOperations": [
          "create",
          "rename",
          "delete"
        ]
      },
      "applyEdit": true,
      "symbol": {
        "symbolKind": {
          "valueSet": [
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            19,
            20,
            21,
            22,
            23,
            24,
            25,
            26
          ]
        }
      },
      "executeCommand": {
        "dynamicRegistration": false
      },
      "didChangeWatchedFiles": {
        "dynamicRegistration": true
      },
      "workspaceFolders": true,
      "configuration": true,
      "codeLens": {
        "refreshSupport": true
      },
      "fileOperations": {
        "didCreate": false,
        "willCreate": false,
        "didRename": true,
        "willRename": true,
        "didDelete": false,
        "willDelete": false
      }
    },
    "textDocument": {
      "declaration": {
        "linkSupport": true
      },
      "definition": {
        "linkSupport": true
      },
      "implementation": {
        "linkSupport": true
      },
      "typeDefinition": {
        "linkSupport": true
      },
      "synchronization": {
        "willSave": true,
        "didSave": true,
        "willSaveWaitUntil": true
      },
      "documentSymbol": {
        "symbolKind": {
          "valueSet": [
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            19,
            20,
            21,
            22,
            23,
            24,
            25,
            26
          ]
        },
        "hierarchicalDocumentSymbolSupport": true
      },
      "formatting": {
        "dynamicRegistration": true
      },
      "rangeFormatting": {
        "dynamicRegistration": true
      },
      "rename": {
        "dynamicRegistration": true,
        "prepareSupport": true
      },
      "codeAction": {
        "dynamicRegistration": true,
        "isPreferredSupport": true,
        "codeActionLiteralSupport": {
          "codeActionKind": {
            "valueSet": [
              "",
              "quickfix",
              "refactor",
              "refactor.extract",
              "refactor.inline",
              "refactor.rewrite",
              "source",
              "source.organizeImports"
            ]
          }
        },
        "resolveSupport": {
          "properties": [
            "edit",
            "command"
          ]
        },
        "dataSupport": true
      },
      "completion": {
        "completionItem": {
          "snippetSupport": true,
          "documentationFormat": [
            "markdown",
            "plaintext"
          ],
          "resolveAdditionalTextEditsSupport": true,
          "insertReplaceSupport": true,
          "deprecatedSupport": true,
          "resolveSupport": {
            "properties": [
              "documentation",
              "detail",
              "additionalTextEdits",
              "command"
            ]
          },
          "insertTextModeSupport": {
            "valueSet": [
              1,
              2
            ]
          }
        },
        "contextSupport": true
      },
      "signatureHelp": {
        "signatureInformation": {
          "parameterInformation": {
            "labelOffsetSupport": true
          }
        }
      },
      "documentLink": {
        "dynamicRegistration": true,
        "tooltipSupport": true
      },
      "hover": {
        "contentFormat": [
          "markdown",
          "plaintext"
        ]
      },
      "foldingRange": {
        "dynamicRegistration": true
      },
      "callHierarchy": {
        "dynamicRegistration": false
      },
      "publishDiagnostics": {
        "relatedInformation": true,
        "tagSupport": {
          "valueSet": [
            1,
            2
          ]
        },
        "versionSupport": true
      },
      "linkedEditingRange": {
        "dynamicRegistration": true
      }
    },
    "window": {
      "workDoneProgress": true,
      "showMessage": null,
      "showDocument": {
        "support": true
      }
    }
  },
  "initializationOptions": {
    "settings": {
      "java": {
        "codeGeneration": {
          "toString": {
            "limitElements": 0,
            "listArrayContents": true,
            "skipNullValues": false,
            "codeStyle": "STRING_CONCATENATION",
            "template": "${object.className} [${member.name()}=${member.value}, ${otherMembers}]"
          },
          "generateComments": false,
          "useBlocks": false,
          "hashCodeEquals": {
            "useInstanceof": false,
            "useJava7Objects": false
          }
        },
        "format": {
          "onType": {
            "enabled": true
          },
          "comments": {
            "enabled": true
          },
          "enabled": true,
          "tabSize": 4,
          "insertSpaces": true
        },
        "progressReports": {
          "enabled": true
        },
        "foldingRange": {
          "enabled": true
        },
        "completion": {
          "importOrder": [
            "java",
            "javax",
            "com",
            "org"
          ],
          "favoriteStaticMembers": [
            "org.junit.Assert.*",
            "org.junit.Assume.*",
            "org.junit.jupiter.api.Assertions.*",
            "org.junit.jupiter.api.Assumptions.*",
            "org.junit.jupiter.api.DynamicContainer.*",
            "org.junit.jupiter.api.DynamicTest.*",
            "org.mockito.Mockito.*",
            "org.mockito.ArgumentMatchers.*",
            "org.mockito.Answers.*"
          ],
          "guessMethodArguments": true,
          "overwrite": true,
          "enabled": true,
          "filteredTypes": [
            "java.awt.*",
            "com.sun.*"
          ],
          "maxResults": 10
        },
        "maxConcurrentBuilds": 1,
        "autobuild": {
          "enabled": true
        },
        "selectionRange": {
          "enabled": true
        },
        "import": {
          "exclusions": [
            "**/node_modules/**",
            "**/.metadata/**",
            "**/archetype-resources/**",
            "**/META-INF/maven/**"
          ],
          "maven": {
            "enabled": true
          },
          "gradle": {
            "enabled": true,
            "wrapper": {
              "enabled": true
            },
            "offline": {
              "enabled": false
            }
          }
        },
        "saveActions": {
          "organizeImports": true
        },
        "implementationsCodeLens": {
          "enabled": false
        },
        "signatureHelp": {
          "enabled": true
        },
        "referencesCodeLens": {
          "enabled": false
        },
        "maven": {
          "downloadSources": false,
          "updateSnapshots": false
        },
        "trace": {
          "server": "off"
        },
        "configuration": {
          "updateBuildConfiguration": "automatic",
          "checkProjectSettingsExclusions": true
        },
        "errors": {
          "incompleteClasspath": {
            "severity": "warning"
          }
        },
        "dependency": {
          "packagePresentation": "flat"
        },
        "project": {
          "importHint": true,
          "importOnFirstTimeStartup": "automatic",
          "referencedLibraries": [
            "lib/**/*.jar"
          ],
          "resourceFilters": [
            "node_modules",
            ".metadata",
            "archetype-resources",
            "META-INF/maven"
          ]
        },
        "imports": {
          "gradle": {
            "wrapper": {
              "checksums": []
            }
          }
        },
        "sources": {
          "organizeImports": {
            "staticStarThreshold": 99,
            "starThreshold": 99
          }
        },
        "server": {
          "launchMode": "Hybrid"
        },
        "showBuildStatusOnStart": {
          "enabled": false
        }
      }
    },
    "extendedClientCapabilities": {
      "progressReportProvider": true,
      "classFileContentsSupport": true,
      "classFileContentsSupport": true,
      "overrideMethodsPromptSupport": true,
      "hashCodeEqualsPromptSupport": true,
      "advancedOrganizeImportsSupport": true,
      "generateConstructorsPromptSupport": true,
      "generateToStringPromptSupport": true,
      "advancedGenerateAccessorsSupport": true,
      "advancedExtractRefactoringSupport": true,
      "moveRefactoringSupport": true,
      "resolveAdditionalTextEditsSupport": true
    },
    "bundles": [
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/com.microsoft.java.test.plugin-0.28.0.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/com.microsoft.jdtls.ext.core-0.5.1.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/dg.jdt.ls.decompiler.cfr-0.0.2-201802221740.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/dg.jdt.ls.decompiler.common-0.0.2-201802221740.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/dg.jdt.ls.decompiler.fernflower-0.0.2-201802221740.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/dg.jdt.ls.decompiler.procyon-0.0.2-201802221740.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/io.projectreactor.reactor-core.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/java.debug.plugin.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/jdt-ls-commons.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/jdt-ls-extension.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.apiguardian_1.1.0.v20190826-0900.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.eclipse.jdt.junit4.runtime_1.1.1200.v20200214-0716.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.eclipse.jdt.junit5.runtime_1.0.900.v20200513-0617.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.jupiter.api_5.6.0.v20200203-2009.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.jupiter.engine_5.6.0.v20200203-2009.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.jupiter.migrationsupport_5.6.0.v20200203-2009.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.jupiter.params_5.6.0.v20200203-2009.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.platform.commons_1.6.0.v20200203-2009.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.platform.engine_1.6.0.v20200203-2009.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.platform.launcher_1.6.0.v20200203-2009.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.platform.runner_1.6.0.v20200203-2009.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.platform.suite.api_1.6.0.v20200203-2009.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.vintage.engine_5.6.0.v20200203-2009.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.opentest4j_1.2.0.v20190826-0900.jar",
      "/home/user/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.reactivestreams.reactive-streams.jar"
    ],
    "workspaceFolders": [
      "file:///path/to/file/folder",
      "file:///home/user",
      "file:///other/workspace/folder"
    ]
  },
  "workDoneToken": "1",
  "workspaceFolders": [
    {
      "uri": "file:///path/to/file/folder",
      "name": "Desktop"
    },
    {
      "uri": "file:///home/user",
      "name": "user"
    },
    {
      "uri": "file:///other/workspace/folder",
      "name": "Organisation"
    }
  ]
}
yyoncho commented 1 year ago

So it crashes right away... Can you do M-x lsp-workspace-folders-remove and keep only one of the folders preferably the simplest project? Also, can you check if there is a log in lsp-java-workspace-dir? I don't know what to try next...

opensource-philosophy commented 1 year ago

I deleted every folder available using M-x lsp-workspace-folders-remove and reinitialized the project. I am already working with an example project with the simplest possible structure. There is just an empty .gitkeep file in lsp-java-workspace-dir. The problem is neither the Emacs Version (28.2) nor the java Version (19)?

yyoncho commented 1 year ago

It is not the emacs version. It is something in jdtls/java version. Can you try a different java version? (make sure to delete lsp-java-workspace-dir when switching versions). Can you remove that setting as well:

  (setq lsp-java-configuration-runtimes '[(:name "JavaSE-19"
                                                 :path "/usr/lib/jvm/java-19-openjdk/"
                                                 :default t)]))
opensource-philosophy commented 1 year ago

How do I use a different java version? I now changed

    (setenv "JAVA_HOME"  "/usr/lib/jvm/java-11-openjdk")
    (setq lsp-java-java-path "/usr/lib/jvm/java-11-openjdk/bin/java")

The directories exist, of course. I commented out the code you highlighted, deleted the workspace-dir and re-installed the jdtls, but the problem persists.

yyoncho commented 1 year ago

You use update-java-alternatives binary (available on debian). This will allow also using M-x lsp-start-plain. (And again, don't forget to flush lsp-java-workspace-dir after each switch)

opensource-philosophy commented 1 year ago

Now I am on arch-linux, so there is no update-java-alternatives, for me but It seems to be archlinux-java. I successfully changed the version, adjusted the environment and java path, deleted the workspace and still got the same problem.

roboli commented 9 months ago

Reinstalling jdts worked for me: lsp-install-server

programmador commented 9 months ago

For me just sudo archlinux-java set java-17-openjdk helped. 11 was not working.

luk3rr commented 2 months ago

run lsp-update-server