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

JAVA_Home should be right but still shows "Note Java 8 can still be used in your own projects" #664

Closed
doggy8088 opened this issue Aug 8, 2021 · 8 comments
Assignees
Labels

Comments

@doggy8088
Copy link

Describe the bug

I think my Java setup in my Visual Studio Code should be right. But this extension still show me this:

Spring Tools Language Server requires Java 11 or higher to be launched. Current Java /usr/lib/jvm/java-8-openjdk-amd64/bin/java. (Note Java 8 can still be used in your own projects. Java 11 is only required to launch the Spring Tools Language Server process)

Source: Spring Boot Tools (Extension)

To Reproduce

  1. Initialize a Spring Boot project using this:

    https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.5.3&packaging=jar&jvmVersion=11&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies=lombok,web
  2. Use `Remote-SSH: Connect to Host...' open Spring Boot project

  3. Open MAVEN view in EXPLORER, expand demo node, click the + sign in the Dependencies noe

  4. Search for spring-boot-starter-validation, choose the org.springframework.boot one.

  5. The VSCode will show this message immediately.

    image

  6. My JAVA_HOME should be right.

    image

  7. The VSCode setting is empty.

    image

Sample

Here is my sample project:

https://github.com/doggy8088/spring-boot-demo

@doggy8088
Copy link
Author

It seems I have to restart VS Code Server on Host.

F1 > Remote-SSH: kill VS Code Server on Host...

@martinlippert martinlippert added for: vscode something that is specific for VSCode type: install-issue and removed status: waiting-for-triage labels Aug 9, 2021
@martinlippert
Copy link
Member

The error message that you mentioned above looks like the Spring Boot Tools extension is picking up a JDK8 to run the language server process (a tooling-internal process, not related to your projects), but it needs JDK11. I don't exactly know why the JDK8 is selected instead of the JDK11 that you have in your JAVA_HOME environment variable... :-(

In case this problem persists, you can specify which JDK the Spring Boot tools should use internally (again, just internally, not for your project) via the settings:

"spring-boot.ls.java.home": "/usr/lib/jvm/java-11-openjdk-amd64/bin/java"

(or whatever the right path to the Java executable of your JDK11 install is)

@doggy8088
Copy link
Author

@martinlippert

I finally found a way to reproduce the problem.

  1. VSCode User Settings

    {
        "java.home": "/usr/lib/jvm/java-11-openjdk-amd64",
        "java.debug.settings.hotCodeReplace": "auto",
        "java.configuration.runtimes": [
            {
                "name": "JavaSE-1.8",
                "path": "/usr/lib/jvm/java-8-openjdk-amd64/",
                "sources": "/usr/lib/jvm/java-8-openjdk-amd64/src.zip",
                "default": true
            },
            {
                "name": "JavaSE-11",
                "path": "/usr/lib/jvm/java-11-openjdk-amd64",
                "sources": "/usr/lib/jvm/java-11-openjdk-amd64/lib/src.zip",
                "javadoc": "https://docs.oracle.com/en/java/javase/11/docs/api"
            }
        ]
    }
  2. My JAVA_HOME environment variable

    /usr/lib/jvm/java-8-openjdk-amd64
  3. My Spring Boot project created using Java 11.


I added "spring-boot.ls.java.home": "/usr/lib/jvm/java-11-openjdk-amd64/bin/java" to my settings.json. Kill my VS Code Host. The error still exists.

image

@doggy8088
Copy link
Author

@martinlippert

I found a way to workaround this problem.

sudo update-alternatives --set java /usr/lib/jvm/java-11-openjdk-amd64/bin/java

@doggy8088
Copy link
Author

@martinlippert

I think this might works. I tested without any error:

"spring-boot.ls.java.home": "/usr/lib/jvm/java-11-openjdk-amd64"

@doggy8088
Copy link
Author

@martinlippert I think STS4 can read "java.home" user setting by default if it's been defined. So that I don't have to setup "spring-boot.ls.java.home" to a JDK path manually.

@martinlippert
Copy link
Member

@martinlippert I think STS4 can read "java.home" user setting by default if it's been defined. So that I don't have to setup "spring-boot.ls.java.home" to a JDK path manually.

Agree, exactly what @BoykoAlex is already implementing at the moment... :-)

@martinlippert
Copy link
Member

This is covered by the latest changes, I think, which is looking at the STS4 specific property first and tries java.home next, if the STS4 property is not set or not set to an existing JDK.

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

No branches or pull requests

3 participants