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

How to configure JDK in Intellij on Fedora Silverblue? #3

Closed
fwilhe opened this issue Dec 28, 2018 · 33 comments
Closed

How to configure JDK in Intellij on Fedora Silverblue? #3

fwilhe opened this issue Dec 28, 2018 · 33 comments
Assignees
Labels
question Further information is requested

Comments

@fwilhe
Copy link

fwilhe commented Dec 28, 2018

Hello,

I'm trying out Fedora Silverblue, and I don't get IntelliJ configured with an 'sdk' (in IntelliJ terms, so the openjdk dev environment).

  • What I did is: Install openjdk-dev via rpm-ostree
    • rpm-ostree install java-11-openjdk-devel
  • Install IntelliJ using flatpak install flathub com.jetbrains.IntelliJ-IDEA-Community

Open jdk is available in /usr/lib/jvm/java-openjdk/bin/

$ ls /usr/lib/jvm/java-openjdk/bin/
jaotc      javac    ....

Still, when I start IntelliJ, and try to create a new project, I can't configure this JDK. I don't find the jvm dir in /usr/lib. I guess this is due to how flatpak works, but I'm not sure if I understand that well enough.

Can some one explain what I need to do, and how flatpak and rpm-ostree integrate?

@TingPing
Copy link
Member

Host applications have nothing to do with Flatpaks.

I don't use Java myself it looks like there is a bundled one at /app/idea-IC/jre64/ but really this should be using org.freedesktop.Sdk.Extension.openjdk11 and I'm not sure why it isn't (CC @x80486)

@x80486
Copy link
Collaborator

x80486 commented Dec 28, 2018

Hi @fwilhe, I knew this is one of the comments/issues I was expecting ALL the time to show up here 😉

I know it's somehow strange, but with Flatpaks, that kind of workflow changes a little bit; like TingPing said: host applications have nothing to do with Flatpaks.

I honestly don't know much technically about Flatpaks, but so far, I can tell you that anything I install in my home directory, provided the artifact have home access, always works as-is. Being said that, you can try:

  1. Install the OpenJDK from the Sdk Extensions – if you need version 8.x you would need to wait some more time until Add OpenJDK8 flathub#750 is merged and somebody updates/rewrites it for Freedesktop 18.08. Once installed (and the IDE restarted) you will have the SDK "visible" in /usr/lib/sdk/openjdkXY/jvm/openjdk-XY/.
  2. Install the OpenJDK / Oracle JDK using any of the Version Managers (and actually for whatever SDK you are looking for) available out there – I would recommend asdf, that's what I use; in this case it would be installed in your home directory, so ALL problems solved. The advantage of this approach is that you can use it within the IDE, as well as on the host/laptop/desktop.

** There is also jabba (only for Java).

@x80486 x80486 self-assigned this Dec 28, 2018
@fwilhe
Copy link
Author

fwilhe commented Dec 28, 2018

Hi @TingPing and @x80486,

thanks for the very quick replies 👍

I solved the issue by manually downloading a openjdk build from https://adoptopenjdk.net/ and putting it into my home directory for now. Not great, but good enough for now.

I'd still like to better understand how this works. My mental model of Flatpak is that applications are containerized, similar to Docker, so they don't share the root-fs with my machine, right? This means my issue was not at all related to the use of Fedora Silverblue, would have been the same with Flatpak on any other distro. I assume the home directory is automatically mounted, right?

Should I close this issue? From my perspective, at least a good workaround is provided.

@x80486
Copy link
Collaborator

x80486 commented Dec 28, 2018

I'd still like to better understand how this works. My mental model of Flatpak is that applications are containerized, similar to Docker, so they don't share the root-fs with my machine, right? This means my issue was not at all related to the use of Fedora Silverblue, would have been the same with Flatpak on any other distro. I assume the home directory is automatically mounted, right?

The way I think about it is like that, but @TingPing might have more technical details. And yes, what you are facing here will apply to all other distros as well. I use Arch Linux and it's the same stuff.

Again, I would recommend you to use a Version Manager; what you did is somehow what they do, but you would have to do (a lot of) manual changes to JAVA_HOME and what not if you are planning to maintain several versions of a given SDK – and actually that applies as well to any other SDKs / platforms. There is also this thing with Java certificates that might bite you back later on, so that's kind of my advice 😎

@TingPing
Copy link
Member

Installing org.freedesktop.Sdk.Extension.openjdk11 is a way better solution than downloading binaries from a site and shoving them into HOME imo.

@fwilhe
Copy link
Author

fwilhe commented Dec 28, 2018

I tried installing openjdk via flatpak, but I could not locate it in IntelliJ's file open dialog. Do you know the path I have to look for?

@x80486
Copy link
Collaborator

x80486 commented Dec 28, 2018

  1. Once installed (and the IDE restarted) you will have the SDK "visible" in /usr/lib/sdk/openjdkXY/jvm/openjdk-XY/

Let's say you installed org.freedesktop.Sdk.Extension.openjdk11, so it will be at /usr/lib/sdk/openjdk11/jvm/openjdk-11.0.1 – you might need to restart the IDE.

screenshot from 2018-12-28 15-33-02

@NeroVanbiervliet
Copy link

Thanks for the help, worked for me!

But what is the purpose of sandboxing this hard?
It leads to lots of duplication of libraries: systemwide and in the flatpak sandbox.

@x80486
Copy link
Collaborator

x80486 commented Dec 29, 2018

Rewind some years and you would have had the same question(s) about so many things in Linux, in general.

Flatpak is somehow starting...and it's looking good so far, you can tell 😉

Eventually, there might be some applications that cannot offer the best experience one can ask for...but good enough for now. Generally speaking, in my opinion, all of this will be improved with time – and sandboxing is great, just break it when you have to 🤣

@TingPing
Copy link
Member

TingPing commented Dec 29, 2018

@NeroVanbiervliet Sandboxing makes it portable and secure. Developers don't care about portability or security in their IDEs they just want to get things done. So yea its a weird fit unless a lot of work is put into it.

@TheOneandOnlyJakfrost
Copy link

Hello @fwilhe
I have been struggling with this issue somewhat over the past number of months. If you check out Apache Netbeans flatpak for instance, it uses the runtime extensions for openjdk 10. So in Netbeans flatpak, I can access the openjdk 10 library with no noticeable issues. It does not see the layered openjdk 8, or the Oracle Jdk 8/10/11, for those you need to update your environment $PATH in order to use, and things like openJavafx runtimes are problems. So far I have found that for flexibility on Silverblue when using an IDE it is best to go with the fedora-toolbox pet container. In it, you can use dnf and stow, and pretty much whatever IDE you desire. It is based upon the podman and buildah combination used for containers on Silverblue, and it's process is still your user process as far as the immutable os is concerned. For IDEA used in the fedora-toolbox container for example, you merely copy over the usual binary from jetbrains and unzip it into your directory of choice like you normally would with Fedora Workstation, then run idea.sh and there ya go. You will likely still need to tweak your path, and you still have to get scenebuilder from gluuon as well as openjfx if you do JavaFx development, but the container is by far the easiest way to set everything up. You install it with 'rpm-ostree install fedora-toolbox', after 'systemctl reboot' you create a container by using 'fedora-toolbox create' and enter it with fedora-toolbox enter, once you have created one.

@TheOneandOnlyJakfrost
Copy link

TheOneandOnlyJakfrost commented Jan 15, 2019

@x80486
I was interested in helping out with the flatpak a bit if you don't mind. One thing I noticed in your json file is the runtime is listed as the freedesktop.sdk, and should be the Platform (org.freedesktop.Platform). Also, I was curious why you chose the freedesktop over gnome, since gnome's rt has freedesktop plus added gnome-ish things. I was able to build it with the gnome platform runtime and the gnome sdk. I agree with the use of extensions to provide base support for things like java, and I think you are only concerned with the SDK's when using that, plus I think you can comma separate list them in the SDK section.
So I was able to install your flatpak with my small modification to the json file for the gnome platform and sdk. While I was looking at that I was also checking into extensions, and how to specify them.I am going to add all of the openjdk extensions I can find and see if I can get a better build from it. I'll keep you posted.

@TheOneandOnlyJakfrost
Copy link

@NeroVanbiervliet

But what is the purpose of sandboxing this hard?

What the intent is revolves around protecting your base OS functionality by making it immutable. The immediate benefit to developers is being able to play around with setups in either flatpaks or pet containers, where they have TOTAL control of it's environment, and where if they break something, it has no affect on the host OS. The drawbacks of Docker and it's daemon requirement are avoided in Silverblue with Podman and Buildah, with Skopeo rounding them out with some added utility. This facilitates the fedora-toolbox pet container, which is based on the buildah/podman combo for daemonless containers. The separation of Host OS and App goes even further when you look at updates and how they are applied independently of each other.

@TheOneandOnlyJakfrost
Copy link

I tried installing openjdk via flatpak, but I could not locate it in IntelliJ's file open dialog. Do you know the path I have to look for?

You cannot install openjdk as a flatpak on Fedora Silverblue, you can however layer it with 'rpm-ostree install ', then 'systemctl reboot' to use the new image. Once you have it installed and the system rebooted, you will need to add it to your environment variable $PATH in order for any flatpak you run to access it directly. This can be done for your home dir since you are the owner of any process you start, including a flatpak'd application.

@TheOneandOnlyJakfrost
Copy link

@TingPing

Developers don't care about portability or security in their IDEs they just want to get things done.

But they do care about breaking their precious setup. They also seem to care how their app runs wanting the best recommended environment setup for it, which is understandable. Being able to provide their users with consistency across the machines they use it on is how you get more users. The lack of needing to concern the developer with selinux or abstract kernel components, and allowing them to tightly control versioning of their support libraries and not having to rely on or work around missing dependencies at install time should translate into happier users and developers. In practice, like all new things, Silverblue can be a challenge.

@x80486
Copy link
Collaborator

x80486 commented Jan 15, 2019

I was interested in helping out with the flatpak a bit if you don't mind.

All right, but I don't know how to give you write access to this repository 😕

One thing I noticed in your json file is the runtime is listed as the freedesktop.sdk, and should be the Platform (org.freedesktop.Platform). Also, I was curious why you chose the freedesktop over gnome, since gnome's rt has freedesktop plus added gnome-ish things. I was able to build it with the gnome platform runtime and the gnome sdk. I agree with the use of extensions to provide base support for things like java, and I think you are only concerned with the SDK's when using that, plus I think you can comma separate list them in the SDK section.

The choice of org.freedesktop.Sdk over org.freedesktop.Platform was not by mistake; it was a suggestion that I didn't know. If the manifest is written in such a way, users can install any Sdk Extension individually and then it will be automatically mounted because it's mentioned in the base runtime. That should also answer the question of why this doesn't have any Sdk Extension bundled by default – it's not needed, and if so, just install it individually and it will be available at /usr/lib/sdk/.

So I was able to install your flatpak with my small modification to the json file for the gnome platform and sdk. While I was looking at that I was also checking into extensions, and how to specify them.I am going to add all of the openjdk extensions I can find and see if I can get a better build from it. I'll keep you posted.

I'm interested to know why would you think using the GNOME platform would be better? Right now the Flatpak does not have a single dependency on anything GNOME-specific, so it can take fully advantage of a slimmer runtime, among other things. You might see GTK 2.x included (as far as I know also removed from GNOME 3.30) and it's only because there are some extensions that will blow up the artifact if that's not present/included – which is exactly what happens on most rolling distros today if you install the .tar.gz release from JetBrains.

@TheOneandOnlyJakfrost
Copy link

@x80486

All right, but I don't know how to give you write access to this repository

I forked it and cloned it locally so I can issue a pull request no?

The choice of org.freedesktop.Sdk over org.freedesktop.Platform was not by mistake; it was a suggestion that I didn't know. If the manifest is written in such a way, users can install any Sdk Extension individually and then it will be automatically mounted because it's mentioned in the base runtime.

Okay, I wasn't aware of that, I wonder if that means the SDK is a runtime as well? I haven't read that anywhere in any of the documents I reviewed so far for Flatpak's. As for the Gnome platform, I didn't think it was that much larger and gives some extra's if there is someone using Gnome with the IDE. In any case I was more meaning the Platform vs SDK thing, and it built fine with the gnome variation.

You might see GTK 2.x included (as far as I know also removed from GNOME 3.30) and it's only because there are some extensions that will blow up the artifact if that's not present/included – which is exactly what happens on most rolling distros today if you install the .tar.gz release from JetBrains.

I did, it is gone from Gnome 3.x, and I wasn't aware that caused issues with the jetbrains site release of CE. Although, in all fairness, there are plenty other packages using the GTK 2.x lib so I am certain it is installed in the standard Fedora workstation.

@TheOneandOnlyJakfrost
Copy link

@x80486

All right, but I don't know how to give you write access to this repository

Hi, I was able to get the flatpak to use the extensions using my modified flatpak manifest. The extensions have to be installed in order to use them in the IDE, but I pointed to the openjdk 10 extension and was able to create and compile then run a simple hello world java application after building and installing the IDE. I was going to commit the changes to my fork of your repo. I should then be able to submit a pull request and you can either merge it or not as you see fit. You already have done all the heavy lifting with your IDEA flatpak and I wanted to help since I use IDEA for my Java and JavaFX development projects, and am testing Silverblue out.

@TheOneandOnlyJakfrost
Copy link

Hi @TingPing and @x80486,

thanks for the very quick replies +1

I solved the issue by manually downloading a openjdk build from https://adoptopenjdk.net/ and putting it into my home directory for now. Not great, but good enough for now.

I'd still like to better understand how this works. My mental model of Flatpak is that applications are containerized, similar to Docker, so they don't share the root-fs with my machine, right? This means my issue was not at all related to the use of Fedora Silverblue, would have been the same with Flatpak on any other distro. I assume the home directory is automatically mounted, right?

Should I close this issue? From my perspective, at least a good workaround is provided.

Hello,
If you would like to try my test build of the IDEA flatpak with openJDK 10 and 11 support it can be done with the following command ... 'flatpak install --user http://repo-test.flathub.org:8080/build-repo/1205/com.jetbrains.IntelliJ-IDEA-Community.flatpakref'. To get the libraries for the openjdk10&11 set up in your IDE, you have to open project structure once you start IDEA. There you select Project from the tree on the left to allow you to setup the jdk(s). When you go to add a sdk you will have to browse to /var/lib/flatpak/runtime where you will find the three openjdk extensions, version 9 seems to be having issues right now so you won't be able to set it up.

@TheOneandOnlyJakfrost
Copy link

Hello @fwilhe
I was in error about the IDEA ide. If you install the extensions from flathub for java by a command such as this flatpak install flathub org.freedesktop.Sdk.Extension.openjdk9 org.freedesktop.Sdk.Extension.openjdk10 org.freedesktop.Sdk.Extension.openjdk11 you will get openjdk 9, 10 , and 11 in /usr/lib/sdk/jdk/jvm/jdk. Sorry for any confusion this may have caused you.

@ateebahmed
Copy link

I also have the same problem on Fedora Workstation where I have jdk 7,8 and 11 but can't access any of them, it would be great if we could allow a file or folder to be used by the app as I don't want to install JDK again separately for flatpak app.

@TheOneandOnlyJakfrost
Copy link

TheOneandOnlyJakfrost commented Jan 23, 2019

I also have the same problem on Fedora Workstation where I have jdk 7,8 and 11 but can't access any of them, it would be great if we could allow a file or folder to be used by the app as I don't want to install JDK again separately for flatpak app.

If you are using Fedora Workstation (proper) as opposed to Silverblue or Atomic Host it should be merely a point of making the correct configuration settings in the IDEA IDE for libraries and runtimes, even if you are running the IDE in a flatpak. On Silverblue, openjdk 9 Extension from Flathub fails to run for, it's directory is seen by the IDEA ide as not having any java SDK, even though it appears to be similar or the same as openjdk 10 Extension for example. Plus versions of JDK's prior to 9 are not built as extension for the flatpak apps. Also, it is important to remember the Workstation Fedora is a standard Linux workstation, and has a directory structure that is known by all, while Silverblue has an immutable os (rpm-ostree) and it has only /var and /etc as writable, with root (/) being immutable. When the image of the OS is mounted it binds /usr to /var/usr and /home to /var/home, and on. What this means in practice is that when you cd into /usr/lib you are actually in /var/usr/lib in
Silverblue, and this continues for all of the "need write access" os directories such as /proc. For the JDK's from Oracle for example, Whether on Fedora Workstation or Fedora Silverblue I just install them into my home directory in a folder called jdks. The Fedora repo includes openjdk 8, and 11, and I imagine openjdk 12 is available on rawhide if you prefer bleeding edge. I hope that help you.

@ateebahmed
Copy link

@TheOneandOnlyJakfrost I have openjdk 7, 8 and 11 installed in /usr/lib/jvm but when I select the SDK directory for JDK, it does not show up in /usr/lib although it has 755 permission which I think should be sufficient for IDE to detect the jdk but that's not the case so I have done the same and installed another JDK inside /home and pointed IDE to that JDK. I also don't understand how JDK 9, 10 and 11 are installed in org.freedesktop.{whatever package that is} as I tried to find such JDKs but couldn't.

@TheOneandOnlyJakfrost
Copy link

I also don't understand how JDK 9, 10 and 11 are installed in org.freedesktop.{whatever package that is} as I tried to find such JDKs but couldn't.

If you are referring to the extensions, you can find them from the terminal with the command flatpak remote-ls flathub that should give you a listing of the available flatpaks at flathub (assuming you named the flathub repo that when you configured it). Look for the org.freedesktop.Sdk.Extension.openjdk then issue the command flatpak install flathub org.freedesktop.Sdk.Extension.openjdk<version> from the terminal and you should see the installation progress or at least get an error that it didn't. If you are unsure what repo's you have configured just type flatpak remotes to get a list.

@TheOneandOnlyJakfrost
Copy link

TheOneandOnlyJakfrost commented Jan 23, 2019

@TheOneandOnlyJakfrost I have openjdk 7, 8 and 11 installed in /usr/lib/jvm but when I select the SDK directory for JDK, it does not show up in /usr/lib

If you are running Silverblue, and you are meaning for the library of your jdk that you configure in IDEA's project structure, then mine which were installed by the extensions mentioned are located here for jdk 11 /usr/lib/sdk/openjdk11/jvm/openjdk-11. My runtime comes from a custom I built, but it could also work from the jdk listed above, you have to configure them in the project once you create/open it.

@ateebahmed
Copy link

I have Fedora Workstation and I would like to use the one installed with package manager

@TheOneandOnlyJakfrost
Copy link

TheOneandOnlyJakfrost commented Jan 23, 2019

Okay,

So on workstation the jdk's reside in /usr/lib/jvm/java-11-openjdk for openjdk 11 which is a symlink to the directory. The jre is a symlink shown as jre-11. At least that is how I see it in my pet container. If you look in that /usr/lib/jvm directory you will see another directory (or more depending on how many jdks you installed) that will have an immensly long filename, usually with rolling and fc29 somewhere in the name along with openjdk. Hope that helps.

@ateebahmed
Copy link

So on workstation the jdk's reside in /usr/lib/jvm/java-11-openjdk for openjdk 11 which is a symlink to the directory. The jre is a symlink shown as jre-11. At least that is how I see it in my pet container.

Yes, that is what I was referring to earlier, I can't access that directory from IDEA, I don't see jvm and
sub directories, so can't point my IDE to use those JDKs

@ateebahmed
Copy link

I can't use debugger from IDE as well maybe because internal JRE does not have permission to pick process from outside? Running maven project from home directory

@TheOneandOnlyJakfrost
Copy link

I can't use debugger from IDE as well maybe because internal JRE does not have permission to pick process from outside? Running maven project from home directory

This discussion has largely strayed from the original issue, perhaps we could move it to a more appropriate forum, like https://discussion.fedoraproject.org/top and You could present your topic there. This would have the added benefit of others who may be currently experiencing the same issues, joining with us to find your solution.
You are running a flatpak on the standard Fedora Workstation Distro, that changes things like the details of execution some, but the principles are the same. So for instance, when you installed extensions for the flatpak, on my (Silverblue) system they go to /usr/lib/sdk/openjdk-'verison', on workstation I am not certain where the extensions end up because I haven't tried it.
In either setup, I still have to select the actual folder inside of the openjdk directory named lib so the path to the jdk11 library is actually /usr/lib/jvm/java-11-openjdk/lib/ does that work?
If you go to the fedora discussion site and get setup to sign in we can continue getting through this. I am jakfrost on fedora's sites or on freenode IRC at the #silverblue channel. You are very welcome to continue this conversation there if it would help you solve this. What I will do in the interim when I get a chance is install flatpak on my dev container and try to go through the process for you to get the lib's recognized by the ide. But that will not be today likely as my plate is full later. others like @TingPing may have even more knowledge of your issue than I, and can get us to the solution faster.

@aplatypus
Copy link

I've faced this problem with ordinary Intellij installs in the past. In that case I made my own script to set things likd JAVA_HOME, M2_HOME, etc that don't get exported into the GUI environment.

Not sure it is feasible to have your own custom script wrapper with a flatpak.

@x80486 x80486 added the question Further information is requested label May 29, 2019
@KevinAtSesam
Copy link

For all those doing Java(Scala, Kotlin) development, I would recommend SdkMan! The superhero that we all need, and some might even deserve.

Using SDK man, you have fine control over which versions of JVM you install, which version you use as default, and how they all interact. All within user space.

@x80486
Copy link
Collaborator

x80486 commented Apr 9, 2020

IntelliJ IDEA version 2020.1 (and onwards) will let you download the Java SDK right from the IDE and place it under ${HOME}/.jdks/.

@x80486 x80486 closed this as completed Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

8 participants