microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.7k stars 1.41k forks source link

JAVA_HOME points to sdkman jdk home instead of microsoft Java home #1646

Closed dashorst closed 1 year ago

dashorst commented 1 year ago

The devcontainer.json points to this URL: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/java

The Dockerfile points to this parent container:

ARG VARIANT="17-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT}

Steps to Reproduce:

  1. add remote container files to project
  2. select java
  3. select maven (no node or gradle)
  4. select java 17 (bullseye)
  5. no other extensions
  6. start mvn in the terminal
  7. get error that JAVA_HOME is invalid
$ mvn help:help
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.

JAVA_HOME points to this:

$ echo $JAVA_HOME
/usr/local/sdkman/candidates/java/current

However when I run java --version:

$ java --version
openjdk 17.0.4.1 2022-08-12 LTS
OpenJDK Runtime Environment Microsoft-40354 (build 17.0.4.1+1-LTS)
OpenJDK 64-Bit Server VM Microsoft-40354 (build 17.0.4.1+1-LTS, mixed mode)

And look where it gets its cup of Java from:

$ which java
/usr/lib/jvm/msopenjdk-current/bin/java

This says to me that the configuration of the Java image is not correct.

Literally a week ago this worked without any problems.

Danielv123 commented 1 year ago

I had the same issue with java 11, added the following to .devcontainer.json to fix it.

    "containerEnv": {
        "JAVA_HOME": "/usr/lib/jvm/msopenjdk-current"
    }
nielspardon commented 1 year ago

It seems JAVA_HOME is still correctly set in the following container image tags: 0.205.4-${VARIANT}. If you change your Dockerfile in the following way it should work properly again:

-FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT}
+FROM mcr.microsoft.com/vscode/devcontainers/java:0.205.4-${VARIANT}

Just adding the manual JAVA_HOME env variable was not enough for me since VS Code could not communicate with the Gradle server properly.

@joshspicer since you are the one who last touched containers/java/definition-manifest.json can you help to get this fixed or find the right person who can fix this?

Chuxel commented 1 year ago

It looks like this is an issue with the updated image in its new home at https://github.com/devcontainers/images.

Copied this issue to the new location. Closing here as a dupe - though this does look like a bug.

New issue is https://github.com/devcontainers/images/issues/158