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

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

Open
wheelcomplex opened this issue Apr 16, 2018 · 11 comments
Labels

Comments

@wheelcomplex
Copy link

[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

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).

@fbricon
Copy link
Collaborator

fbricon commented Apr 16, 2018

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?

@wheelcomplex
Copy link
Author

wheelcomplex commented Apr 17, 2018

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

@solarkraft
Copy link

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

@solarkraft
Copy link

solarkraft commented Feb 12, 2019

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.

@martin-jamszolik
Copy link

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!

@notaphplover
Copy link

notaphplover commented Mar 27, 2020

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

@antis81
Copy link

antis81 commented Mar 25, 2021

💡 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.

@achaphiv
Copy link

achaphiv commented Jun 25, 2021

I have my dotfiles shared across multiple computers & operating systems.

I didn't want my vscode config to have a hardcoded path.

So I went with the more machine-specific approach:

$ flatpak install flathub org.freedesktop.Sdk.Extension.openjdk11
$ flatpak override --user com.visualstudio.code --env=JAVA_HOME=/usr/lib/sdk/openjdk11/jvm/openjdk-11

Note that the host java didn't work for me.

Here's the error when running via the vscode integrated terminal:

$ /run/host/usr/lib/jvm/java-11-openjdk/bin/java
/run/host/usr/lib/jvm/java-11-openjdk/bin/java: /usr/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /run/host/usr/lib/jvm/java-11-openjdk/bin/../lib/jli/libjli.so)

@rgrunber
Copy link
Member

As was mentioned a few comments above :

$ flatpak info com.visualstudio.code --file-access /usr/lib/jvm/java-11-openjdk/
hidden

So the JDKs need to be moved to another location or that location needs to be exposed when the VSCode flatpak is running. The only location that might work without any moving is
"java.jdt.ls.java.home": "~/.var/app/com.visualstudio.code/data/vscode/extensions/redhat.java-1.6.0/jre/17.0.1-linux-x86_64/"

On supported platforms, we ship a JDK (17), though this still doesn't solve the problem for those wishing to use a particular version.

@jdneo jdneo added the runtime label Feb 13, 2023
@TheUncleRemus
Copy link

Hi guys I have opened an issue (and also I proposed a solution) to golang/vscode repo, to resolve this situation.
follow the summary

the problem

the problem is generated because the flatpak apps run inside an isolate sandbox (like a container). For this reason we don't have the access to the host-filesystem.

the links

  • issue where you can read my considerations: issue/3063
  • my repo with a solution (designed for go but it can be generalized for every type of tool/language): flapak-vscode-as-go-ide

@TheUncleRemus
Copy link

I can propose to you this workaround:

  • Download the tarball jdk from this link: https://jdk.java.net/21/
  • unpack the jdk-tarball to a non-private path (for flatpak-side), like: $HOME/.java/jdk
  • refers in your flatpak-vscode java (or tool that needs of jadk) configuration the above path (thus: where you have unpacked the jdk tarball)

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

10 participants