Vscode-java: incompatible with flatpak: The java.home variable defined in VS Code settings points to a missing folder

Created on 16 Apr 2018  路  7Comments  路  Source: redhat-developer/vscode-java

[vscode installed by flatpak can not access JAVA_HOME]

I'm not sure is this a bug of vscode-java or flatpack.
Note: flatpak run vscode in a isolated environment.

Environment
  • Operating System: Ubuntu 18.04 X86_64
  • JDK version: oracle JDK 1.8
  • Visual Studio Code version:
  • Java extension version:
Steps To Reproduce
  1. [step 1]
    install flatpak: https://flatpak.org
    install vscode from: https://flathub.org/apps/details/com.visualstudio.code
  2. [step 2]
    install vscode-java and set correct JAVA_HOME/java.home
    try to open/run java code

[attach a sample project reproducing the error]
[attach logs](https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#enable-logging)

Current Result

The java.home/JAVA_HOME variable defined in VS Code settings points to a missing folder

Expected Result

run normal without error.

Additional Informations

JAVA_HOME=/usr/lib/jvm/java-8-oracle

Every thing is OK when run vscode which is installed by .deb file (download from https://code.visualstudio.com/docs/setup/linux).

Most helpful comment

Maybe it's a bit late, but after reading the docs:

The main rules are:

  • These directories are blacklisted: /lib, /lib32, /lib64, /bin, /sbin, /usr, /boot, /root, /tmp, /etc, /app, /run, /proc, /sys, /dev, /var
  • Exceptions from the blacklist: /run/media
  • These directories are mounted under /var/run/host: /etc, /usr

The reason many of the directories are blacklisted is because they already exist in the sandbox such as /usr or are not usable in the sandbox.

Since /usr is mounted at /var/run/host, it worked for me to config my jdk path as follows:

__settings.json__

    ...
    "java.home": "/var/run/host/usr/lib/jvm/java-11-openjdk-amd64"
    ....

Keep in mind that the real path of the JDK in my filesystem is /usr/lib/jvm/java-11-openjdk-amd64

All 7 comments

Looks like the same issue as with #157.

Just to check, can you try to point to a copy of the JDK somwhere under your home directory?

@fbricon it works fine when point java.home to a copy of the JDK somewhere under home directory.
Thanks for your tips.

I ran into this issue today and wasted quite a lot of time on it :c
Is there any workaround?

After reading a bit of Flatpak documentation I think this is a problem with the Flatpak package.
Flatpak tries to sandbox applications, which includes hiding paths from them.

Checking whether java_home is visible:
flatpak info com.visualstudio.code.oss --file-access=/usr/lib/jvm/java-1.11.0-openjdk-amd64/ hidden

This is weird, because the file system is set to "host" (meaning the app should be able to access the complete file system ... with weird limitations). There is talk about things being mounted in /var/run/host/, but there is never clarity about whether they talk about the real path or the path the application sees - either way, the check for /var/run/host/usr/lib/jvm/java-1.11.0-openjdk-amd64/ also returns hidden.

Anyway, this isn't a problem with vscode-java. I'll post an update when/if I find an acceptable workaround.

Edit: I couldn't really find one. Flatpak seems to have system file inaccessability as a design goal, even symlinks don't work.

I ended up copying the folder. Feels stupid.

It also turns out that you can install a JDK and make it visible to a sandboxed application like an IDE with
flatpak install flathub org.freedesktop.Sdk.Extension.openjdk11
you can find it's installation at
/usr/lib/sdk/openjdk11/jvm/openjdk-11

Cheers!

Maybe it's a bit late, but after reading the docs:

The main rules are:

  • These directories are blacklisted: /lib, /lib32, /lib64, /bin, /sbin, /usr, /boot, /root, /tmp, /etc, /app, /run, /proc, /sys, /dev, /var
  • Exceptions from the blacklist: /run/media
  • These directories are mounted under /var/run/host: /etc, /usr

The reason many of the directories are blacklisted is because they already exist in the sandbox such as /usr or are not usable in the sandbox.

Since /usr is mounted at /var/run/host, it worked for me to config my jdk path as follows:

__settings.json__

    ...
    "java.home": "/var/run/host/usr/lib/jvm/java-11-openjdk-amd64"
    ....

Keep in mind that the real path of the JDK in my filesystem is /usr/lib/jvm/java-11-openjdk-amd64

:bulb: FYI

With OpenJDK >11 the following should work:

"java.home": "/var/run/host/usr/lib/jvm/default-runtime",

Am with Manjaro/Arch. Debian may use a different location.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcjolley picture jcjolley  路  3Comments

ronniehicks picture ronniehicks  路  3Comments

ViniciusAtaide picture ViniciusAtaide  路  4Comments

roben picture roben  路  4Comments

protoEvangelion picture protoEvangelion  路  3Comments