5

I have installed VSCode flatpak package.

flatpak install flathub com.visualstudio.code

Now there is a file flatpak-warning.txt

It reads


https://www.flathub.org

| Warning: You are running an unofficial Flatpak version of Visual Studio Code !!! |

Please open issues under: https://github.com/flathub/com.visualstudio.code/issues

This version is running inside a container and is therefore not able to access SDKs on your host system!

To execute commands on the host system, run inside the sandbox:

$ flatpak-spawn --host <COMMAND>

To make the Integrated Terminal automatically use the host system's shell, you can add this to the settings:

{ "terminal.integrated.defaultProfile.linux": "bash", "terminal.integrated.profiles.linux": { "bash": { "path": "/usr/bin/flatpak-spawn", "args": ["--host", "--env=TERM=xterm-256color", "bash"] } } }

This flatpak provides a standard development environment (gcc, python, etc). To see what's available:

$ flatpak run --command=sh com.visualstudio.code $ ls /usr/bin (shared runtime) $ ls /app/bin (bundled with this flatpak)

To get support for additional languages, you have to install SDK extensions, e.g.

$ flatpak install flathub org.freedesktop.Sdk.Extension.dotnet $ flatpak install flathub org.freedesktop.Sdk.Extension.golang $ FLATPAK_ENABLE_SDK_EXT=dotnet,golang flatpak run com.visualstudio.code

You can use

$ flatpak search <TEXT>

to find others.

Now I have OpenJDK installed on system.

java --version
openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.21.10)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.21.10, mixed mode, sharing)

But when I try to create a Java Project it shows no build tools.

Now my question is I can't figure out where to add the lines -

{
    "terminal.integrated.defaultProfile.linux": "bash",
    "terminal.integrated.profiles.linux": {
        "bash": {
          "path": "/usr/bin/flatpak-spawn",
          "args": ["--host", "--env=TERM=xterm-256color", "bash"]
        }
    }
  }

Also I am unable to understand -

$ flatpak-spawn --host <COMMAND>
Payel Senapati
  • 161
  • 1
  • 2
  • 8

3 Answers3

5

I'm not sure if you're still looking for an answer, but here's what worked for me (not using the system SDK, but one that is made as a Flatpak extension):

  1. Check the available Java SDK extensions for Flatpak (those can be accessed by VSCode): flatpak search Sdk | grep -i jdk: jdk search output
  2. Install the one(s) that you want, for example flatpak install org.freedesktop.Sdk.Extension.openjdk17
  3. As instructed in the flatpak-warning.txt file, you can see what is available to your flatpaks (binaries, SDKs,...) by running the flatpak shell with the VSCode command flatpak run --command=sh com.visualstudio.code. The JDK extension installed in step 2 is kept in /usr/lib/sdk in the flatpak hierarchy (at least on my Fedora install, but I think it should be the same on Ubuntu). Confirm by running ls /usr/lib/sdk in the flatpak shell and you should see your SDK there (possibly among other things): listed in /usr/lib/sdk
  4. You need to add this to the VSCode configuration, for me it was in settings.json:
    "java.jdt.ls.java.home": "/usr/lib/sdk/openjdk17/jvm/openjdk-17.0.1/"`,
    "java.configuration.runtimes": [
        {
            "name": "JavaSE-17",
            "path": "/usr/lib/sdk/openjdk17/jvm/openjdk-17.0.1/",
            "default": true
        }
    ],

After this I restarted VSCode and everything worked. BTW when anything that you have to do in the flatpak shell should work just the same in the terminal window of VSCode itself.

1

I am using Linux Mint 21.2. I installed VSCode from the build-in flatpak Software Manager and I encounter the same issue.

First, I think it is quite troublesome to explicitly edit VSCode configuration to access to system SDK.

Secondly, when I turn on Sync, I think the local flatpak VSCode configuration will mess up the online sync-ed version, because VSCode is asking me to merge conflict.

Hence, I rather download VSCode from https://code.visualstudio.com/download and manually install it.

sudo apt install ./code_(whatever_version).deb

VSCode installed in this way will work normally.

0

You can add those lines in settings.json file.

and as mentioned in flatpak-warning.txt run the host command inside sandbox eg:

flatpak-spawn --host java --version