Skip to content

VSCode extension JDK version #612

Closed
Closed

Description

@rubensa

Installed version

  • Spring Boot Extension Pack v0.0.8
  • Spring Boot Dashboard v0.2.0
  • Spring Boot Tools v1.25.0
  • Spring Initializr Java Support v0.7.0

Looks like some code in the latest version is compiled against Java 11 (but prerequisites is JDK 8)

Activating 'vscode-spring-boot' extension
Found java exe: /opt/sdkman/candidates/java/8.0.282.hs-adpt/bin/java
isJavaEightOrHigher => true
Redirecting server logs to /dev/null
ERR: Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/ide/vscode/boot/app/BootLanguagServerBootApp has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)

Also reported here: microsoft/vscode-spring-boot-dashboard#125

Activity

  1. rubensa commented on Mar 19, 2021

    @rubensa
    Author

    As a side note, I have configured the "spring-boot.ls.java.home" setting to point to the desired JDK (verison 8).

  2. Eskibear commented on Mar 19, 2021

    @Eskibear
    Contributor

    I can repro it. I've installed both JDK 11 and 8 on my machine.

    By default. it works well, and logs are:

    Activating 'vscode-spring-boot' extension
    Found java exe: C:\Users\zy199\AppData\Local\Programs\AdoptOpenJDK\jdk-11.0.8.10-hotspot\bin\java.exe
    isJavaEightOrHigher => true
    Redirecting server logs to /dev/null
    ERR: Disabling server log output. No more output will be sent after this.
    Child process connected on port 45556
    

    If I point "spring-boot.ls.java.home" to JDK 8, and reload window, below error occurs, same as above

    Activating 'vscode-spring-boot' extension
    Found java exe: C:\Program Files\Java\jdk1.8.0_281\bin\java.exe
    isJavaEightOrHigher => true
    Redirecting server logs to /dev/null
    ERR: Error: A JNI error 
    ERR: has occurred, please check your installation and try again
    Exception in thread "main" 
    ERR: java.lang.UnsupportedClassVersionError: org/springframework/ide/vscode/boot/app/BootLanguagServerBootApp has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    
    

    So I believe those who has only JDK 8 installed will have the same issue.

  3. martinlippert commented on Mar 19, 2021

    @martinlippert
    Member

    Yes, the extension now requires a JDK11 to run on and the internal check should be updated to reflect that.
    @BoykoAlex Can you have a look and update the internal check to look for a JDK11 (and while doing that, we can also probably remove all the checks looking for tools.jar, since that check isn't been used when running on an JDK >=9 anyway).

  4. added this to the milestone on Mar 19, 2021
  5. martinlippert commented on Mar 19, 2021

    @martinlippert
    Member

    So to quickly fix this, change the settings via "spring-boot.ls.java.home" to point to a JDK >= 11.

  6. rubensa commented on Mar 19, 2021

    @rubensa
    Author

    One question here...
    The extension needs JDK >= 11 to work but how does Spring Boot Dashboard launch my application? Can I make sure that my code is being run with the JDK I'm supposed to be developing to (in this case JDK 8)?

    As far as I know, the Language Support for Java extension knows the Java runtimes I have installed via "java.configuration.runtimes" config setting, and uses the "best match" based on this and "java.version" (if you are using Spring Boot or "maven.compiler.source", or "maven.compiler.release", depending on maven-compiler-plugin version) maven property to decide witch runtime to use for the compilation.
    Does Spring Boot Dashboard extension the same to decide witch java runtime use to launch de application?

  7. kdvolder commented on Mar 19, 2021

    @kdvolder
    Member

    @rubensa about your question...

    TLDR; Setting spring-boot.ls.java.home doesn't change how your project launches. It only the affects STS language server. So it should be fine for your scenario.

    More detailed explanation. It should be possible to control Java home for your project and for the redhat java tooling (which is what the boot dashboard uses to launch your project) independently. The jvm used to launch the sts4 extensions are controlled by spring-boot.ls.java.home configuration key in vscode settings.json. The redhat tooling is configured independently via java.home.

    I was also expecting that you should be able to control the Java home for a specific launch as well from it's launch.json file, but googling a bit for the documentation on this I could only find the list of launch.json option here and it makes no mention of how you set the Java home: https://code.visualstudio.com/docs/java/java-debugging#_configuration-options

    That could be an oversight since just like for STS4, the JVM required to launch redhat Java tooling may not neccessarily be the one that a user wants to launch their own project with.

    Anyway assuming that doc I found is complete, I think you'd have to control the jvm used for launching your project using 'java.home' property in user/workspace settings while spring-boot.ls.java.home controls only the JVM used to launch STS extension's language server.

  8. BoykoAlex commented on Mar 19, 2021

    @BoykoAlex
    Contributor

    Should be fixed in this commit a4513b8

  9. 8 remaining items

  10. martinlippert commented on Mar 25, 2021

    @martinlippert
    Member

    @BoykoAlex Can you take a look to see if we can auto-select a JDK11 if that is around somewhere?

  11. martinlippert commented on Mar 25, 2021

    @martinlippert
    Member
    • Is the error message not helpful enough for users? As they may not understand "Java-based Language Server".

    Yeah, this is because we use the code for various language servers that we implemented in Java. But I agree, the error message should be improved, it doesn't make a lot of sense from the users point of view. It should definitely be more specific.

  12. BoykoAlex commented on Mar 25, 2021

    @BoykoAlex
    Contributor

    @rubensa I noticed this:

    As a side note, I have configured the "spring-boot.ls.java.home" setting to point to the desired JDK (verison 8).

    The "spring-boot.ls.java.home" setting is only to launch Spring Language Server process (i.e heart of the tooling) it has nothing to do with the Java version used in your projects. If your projects require Java 8 they will work just fine with Spring Tools that were launched with Java 11 under the hood.

    @martinlippert myself and @kdvolder looked into finding Java 11 or higher on the system... Currently JDK is being searched in (unless "spring-boot.ls.java.home" is set)

    1. JAVA_HOME environment variable
    2. In PATH environment variable

    Once we find any JDK in any of those steps it is returned. JDT server works similarly, but also checks JDK_HOME, windows registry and "default" location. Finds all of them and then picks the first in the list where version is 11 or higher.
    This feels a bit unpredictable...

    We felt (me and @kdvolder) that the current logic in vscode extensions looking for JDK is ok... but of course we can switch it to just look for JDK until version constraint is satisfied... maybe we should discuss this a bit...
    We felt that the confusion arises because in the Wiki we stated prerequisite for tooling to run is Java 8+, it is not obvious whether java 11 and "spring-boot.ls.java.home" setting to start the tooling or is it the java to work with spring projects. Also the popup is misleading of course (stated above).

    We have corrected the wiki and the popup message so far and hope that it might be ok already without picking JDK on user system somewhat randomly...

  13. rubensa commented on Mar 26, 2021

    @rubensa
    Author

    Yes @BoykoAlex I "had" spring-boot.ls.java.home pointing to JDK 8 (as, It was specified in the doc as the minimun need). Now It's pointing to version 11 (so no problem here anymore).

    When you say "If your projects require Java 8 they will work just fine with Spring Tools that were launched with Java 11 under the hood." That's true, but I want assure that I'm running my app with "the right" JDK my app is supposed to be developed for (so, for example, I do not use any non existing API that exists in a more recent JDK).

    So, for me, predictability is important. If should be "great" to be able to specify the "exact" JDK I want to use (as requested, for example, here: redhat-developer/vscode-java#1684) o, at least that "any" extension Java related uses the "same" mechanism to decide which JDK use to compile/run/anything... my application (that could be different JDK that the extension needs to run itself if the extension has code written in Java).

  14. rubensa commented on Mar 26, 2021

    @rubensa
    Author

    As there are may Java-related extensions (a must should be anything from Java Extension Pack and Spring Boot Extension Pack), provided by different people/organization, is difficult to "unify" it but the idea could be something like:

    • java.home : To specify the JDK path to be used to compile/run/anything the app. This setting could be specified at any scope (User, Remote [Dev Container], Workspace, Folder)
    • extension.prefix.java.home (like spring-boot.ls.java.home): To specify the JDK path to be used by the specific extension. This setting could be specified at any scope (User, Remote [Dev Container], Workspace, Folder)
    • java.configuration.runtimes : Use this for the project as a fallback if java.home is not specified. Also use this if extension.prefix.java.home is not specified for the extension. The "algorithm" to decide the JDK to use from the available runtimes should be documented and should be the same for any extension.
    • If none is set, the extension should do "it's best" to find the available JDKs and use the same documented algorithm to decide the JDK to use form the found ones.
    • Also, there should be a mechanism to check the currently JDK used by the extension itself and the one used to compile/run/anything the project.

    Does this make any sense?

  15. BoykoAlex commented on Mar 26, 2021

    @BoykoAlex
    Contributor

    @rubensa I feel that there is still a bit of misunderstanding... Outlined above is the Java Language Server approach with spring-boot.ls.java.home (i.e. extension.prefix.java.home) in the mix as the second bullet. I don't think that spring-boot.ls.java.home setting fits in this picture at all as it does not attempt to override Java Language Server settings for your project. Your project will be compiled and run only by the JDK/JRE from the Java Language Server settings and the mechanics of finding the JDK for it is just as you outlined above (or https://github.com/redhat-developer/vscode-java#setting-the-jdk)

    spring-boot.ls.java.home setting is around only to launch the Spring Tools Java Language Server application with the specific JDK 11+ if JAVA_HOME is not java 11+. It has nothing to do with the Java settings of your project and it doesn't interfere with the exact Java version you've picked for your project (which would be either java.home or java.configuration.runtimes or JAVA_HOME environment variable - Java LS settings)

    For example Java based IDE such as Eclipse can be launched with Java 11+ but you you can still work in it with Java 8 based projects and pick exact Java 8 version for a project or workspace in Eclipse preferences Java -> Installed JREs. In this example Spring Language Server is Eclipse or Eclipse plugin to be precise and Java -> Installed JREs preference is the equivalent of the Java settings from Java Language Server. (Not sure if this is a great example though ;-))

  16. rubensa commented on Mar 29, 2021

    @rubensa
    Author

    Hi @BoykoAlex

    I understand what you are telling but I was talking about a "wider approach". I was talking about unifying the mechanism for any Java related VSCode extensions to decide which JDK to use for itself and which JDK to use to compile/build/anything your Java project.

  17. martinlippert commented on Mar 30, 2021

    @martinlippert
    Member

    @rubensa I very much agree that a "wider approach" makes sense here and that it would be good to unify the way the different extensions select and use the JDKs on the system. It would be good to find a common ground here to make this easier for the user.

    When looking at this at the broader scope, I think we have two fundamentally different use cases here:

    • (1) the extension itself requires a JDK to run on. The extension usually requires a specific minimum JDK level to run on, due to the extension itself being written in Java and compiled based on a specific minimum Java version.
    • (2) user projects are configured for a specific Java version to compile against and probably can use the same but also a different JDK to run/debug the project.

    Both cases are completely separate from each other and should not be mixed up, I think. Different projects might require different JDKs to compile/run against (even in the same workspace different projects might use different JDKs at the same time). Different extensions might need different JDKs as well to work with (e.g. the RedHat Java extension might use JDK14 in the future, whereas the Spring Boot extension still uses JDK11). So it is hard to come up with some unique setting the user defines (like java.home points to a JDK and we use that for everything). But it is also cumbersome for the user to define the individual JDKs all across the place using different settings and options. That is crazy.

    One approach could be:
    We could come up with a unified way to let users define all the JDKs that are installed on their system (or whatever subset they would like to use). Maybe in some way like the RedHat Java extension defines the project JDKs: https://github.com/redhat-developer/vscode-java#project-jdks - but not specifically for projects, but as a general setting of configured JDKs to use.

    Then, extensions could ask this unified list for a specific JDK (or a compatible one). So instead of searching for a JDK11 on its own, the Spring Boot language server could ask this unified component for a JDK >= 11 and that unified component would whatever Is configured in that list. In case extensions need to compile/run projects from the user, the extension could also lookup the available JDKs from that list and use them to compile/run against (or let the user even select which JDK to use then running an app).

    @Eskibear What do you think?

  18. martinlippert commented on Mar 30, 2021

    @martinlippert
    Member

    @Eskibear Btw, we released an updated version of the VSCode extension yesterday with the fix included, so that the extension checks for a JDK >= 11 and report an error if something else is found or configured appropriately. I am sure we can improve the error message a bit further (and add a link to the settings file to configure the JDK to make it easier to navigate there and find the right config setting), but that is subject to another issue.

    Therefore I am closing this item here. But I would like to continue the discussion around the unified approach to define JDKs and come to a good conclusion there. We should probably extract that discussion into a separate GitHub item. Would you prefer something on the RedHat Java extension side or something over here?

  19. Eskibear commented on Mar 31, 2021

    @Eskibear
    Contributor

    @martinlippert Great to know the issue got mitigated.

    About JDKs, it's also a problem for Java extension itself. As you mentioned, it's easy to mix up JDKs used to launch extensions and run projects. And that's why we pin redhat-developer/vscode-java#1543 on Redhat Java extension repository today.

    A unified component to manage all JDKs is a good idea. We tried that with a unified Configure Java Runtime page in Java extension pack, listing all installed JDKs and attempting to provide an clearer way to configure JDKs for projects. Ideally, an independent "library extension" would be better, with exported APIs allowing other extensions to ask for location of available JDKs.

    Another idea we had before was, to pre-pack a JDK inside the extension (just like what IntelliJ IDEA does). Then you only need to take care of your project JDKs. But the problem is, currently we cannot publish platform-specific extensions in VS Code, meaning that we have to pre-pack JDKs for all platforms together, which is too large.

  20. martinlippert commented on Apr 12, 2021

    @martinlippert
    Member

    A unified component to manage all JDKs is a good idea. We tried that with a unified Configure Java Runtime page in Java extension pack, listing all installed JDKs and attempting to provide an clearer way to configure JDKs for projects. Ideally, an independent "library extension" would be better, with exported APIs allowing other extensions to ask for location of available JDKs.

    Any plans in this direction? Would be awesome if we could collaborate on something like this so that we end up having a component that makes it easier for users to select and use specific JDKs.

    Another idea we had before was, to pre-pack a JDK inside the extension (just like what IntelliJ IDEA does). Then you only need to take care of your project JDKs. But the problem is, currently we cannot publish platform-specific extensions in VS Code, meaning that we have to pre-pack JDKs for all platforms together, which is too large.

    Yeah, I am not a big fan of pre-packaging the JDKs. We do that for the Spring Tools 4 for Eclipse distribution, but it really increases the size of the extension quite a bit - even if it would be possible to select the platform-specific piece. So I don't see this is the best way to proceed.

  21. modified the milestones: , 4.11.0.RELEASE on Apr 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions