java-language-server
java-language-server copied to clipboard
Error with custom JAVA_HOME
Hey! First off thanks for the awesome project! I'm looking at using a development JDK with this extension. However, I'm running into an error trying to configure it.
While digging through it seems there's a custom configuration option called: java.home
, however that doesn't seem to work :sweat_smile:
Specifically I've checked out the custom JDK to a folder called: scratch/jdk/
:
$ ls scratch/jdk/
bin conf demo include jmods legal lib man release
$ ./scratch/jdk/bin/java -version
openjdk version "15-internal" 2020-09-15
OpenJDK Runtime Environment (build 15-internal+0-adhoc..repo)
OpenJDK 64-Bit Server VM (build 15-internal+0-adhoc..repo, mixed mode, sharing)
I've tried setting my configuration to:
{
"java.home": "${workspaceFolder}/scratch/jdk/"
}
and:
{
"java.home": "scratch/jdk/"
}
However both times the language server crashes as it seems to try and use a different java:
00:37:18.451 INFO InferConfig fork Running bazel info output_base ...
00:37:18.469 INFO InferConfig fork Running bazel aquery --output=proto mnemonic(JavaSourceJar, kind(java_library, ...) union kind(java_test, ...) union kind(java_binary, ...)) ...
Loading:
Loading: 0 packages loaded
Analyzing: target //projects/dust:flat_hash_map (0 packages loaded, 0 targets configured)
INFO: Analyzed target //projects/dust:flat_hash_map (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
INFO: Elapsed time: 0.032s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
INFO: Build completed successfully, 0 total actions
00:37:18.514 INFO ScanClassPath jdkTopLevelClasses Searching for top-level classes in the JDK
00:37:18.532 INFO ScanClassPath jdkTopLevelClasses Found 5667 classes in the java platform
Class path:
Doc path:
00:37:18.533 SEVERE Main main java.nio.file.NoSuchFileException: /usr/java
java.lang.RuntimeException: java.nio.file.NoSuchFileException: /usr/java
at org.javacs.JavaHomeHelper.check(JavaHomeHelper.java:83)
at org.javacs.JavaHomeHelper.linuxJavaHome(JavaHomeHelper.java:62)
at org.javacs.JavaHomeHelper.javaHome(JavaHomeHelper.java:30)
at org.javacs.Docs.findSrcZip(Docs.java:53)
at org.javacs.Docs.srcZip(Docs.java:39)
at org.javacs.Docs.<init>(Docs.java:18)
at org.javacs.JavaCompilerService.<init>(JavaCompilerService.java:37)
at org.javacs.JavaLanguageServer.createCompiler(JavaLanguageServer.java:112)
at org.javacs.JavaLanguageServer.compiler(JavaLanguageServer.java:39)
at org.javacs.JavaLanguageServer.lint(JavaLanguageServer.java:61)
at org.javacs.JavaLanguageServer.doAsyncWork(JavaLanguageServer.java:523)
at org.javacs.lsp.LSP.connect(LSP.java:247)
at org.javacs.Main.main(Main.java:30)
Caused by: java.nio.file.NoSuchFileException: /usr/java
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.newDirectoryStream(UnixFileSystemProvider.java:432)
at java.base/java.nio.file.Files.newDirectoryStream(Files.java:475)
at java.base/java.nio.file.Files.list(Files.java:3760)
at org.javacs.JavaHomeHelper.check(JavaHomeHelper.java:81)
... 12 more
[Error - 12:37:18 AM] Connection to server got closed. Server will not be restarted.
Any help would be appreciated here, as I'm trying to figure out how to not have to have a user override a local environment variable for when they only work on this project. So it'd be great if I could just put it in the config.
If you'd like to get the jdk yourself incase you want to repro (NOTE: it's linux x86_64 only), I've been pushing it to a docker image so you can fetch it from:
$ mkdir -p scratch/jdk/
$ docker pull securityinsanity/openjdk-panama-vector:latest -q >/dev/null
$ container_id=$(docker run --rm -it -d securityinsanity/openjdk-panama-vector:latest /bin/bash)
$ docker cp "$container_id:/usr/lib/jvm/java-vectors-openjdk-amd64" scratch/jdk/
$ docker kill "$container_id"
@Mythra this project packages it's own JDK with a limited set of modules. See scripts/link_linux.sh
for more details. The language server is intended to be run using that java runtime. See dist/launch_linux.sh
for an easy way to accomplish that.