29

Before you write me off, please consider that neither of these are answers to my question:


In IntelliJ IDEA 2017.2.6, attempting to add JDK9 as an SDK passes but does not work as the classpaths end up empty. Steps to reproduce:

  1. Open 'Add new SDK dialog'
    (go to Project Settings > Project > Project SDK > New > JDK)
  2. Select JDK 9
    select jdk dialog
  3. Passes, but if you look under SDK > JDK9 classpaths are empty and your code errors out due to base classes not being found. See image:
    no classpaths

In IntelliJ IDEA 2017.3 EAP you get an error about JDK classes not being found. See images below:

  1. Open 'Add new SDK dialog'
    (go to Project Settings > Project > Project SDK > New > JDK)
  2. Select JDK 9
    select jdk dialog
  3. Should pass, but produces error popup
    jdk error popup

Command line compilation of HelloWorld example with jdk9 works as expected.

EDIT: Found an almost-duplicate: Intellij IDEA 2017.2 can't add openjk 9 on Linux Mint 18. Key differences:

  • Linux version: they're using Mint 18, and I'm using Debian Stretch.
  • OpenJDK is the latest from the repo at the moment of writing: 9~b181-4~bpo9+1. Even though is the same version, it still does not work in my case.

EDIT: Another possible duplicate: intellij idea does not see java 9 standard classes

I did not understand the answer from the comments though. Tried setting different names for JDK (9 and 1.9) but it still did not show modules instead of classpaths and classpaths remained empty.

Makoto
  • 104,088
  • 27
  • 192
  • 230
anon2234
  • 291
  • 3
  • 4
  • Possibly related [Debian Bug](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=875584) and the [Failed to find JDK / tools.jar](https://wiki.debian.org/Java/Java9Pitfalls) section in the linked thread. – Naman Nov 15 '17 at 01:36
  • Do you use the latest EAP? It should work fine in it. – y.bedrov Nov 16 '17 at 10:47
  • It seems to persist on 9~b181-4 and IntelliJ IDEA 2017.3.1 (#IU-173.3942.27) – mszymborski Dec 15 '17 at 22:52

2 Answers2

27

Current debian binary package openjdk-9-jre-headless 9~b181-4 contains incorrectly compiled lib/jrt-fs.jar file.
There are 2 filed issues separately on both idea youtrack and also ubuntu launchpad.

As it is indicated here:

Probable reason:
Classes in lib/jrt-fs.jar were compiled by Java 9 with options "-source 8"/"target 8". They should be compiled with "--release 8" option instead (or by Java 8)

A temporary workaround may be replacing /usr/lib/jvm/java-9-openjdk-amd64/lib/jrt-fs.jar with the one from Oracle JDK.
You may also try to recompile the openjdk-9 source using the advised option "--release 8".

Anyway I advice to vote up this issue on the above link to attract more attention by dev team.

Kayvan Tehrani
  • 3,070
  • 2
  • 32
  • 46
  • My gut tells me that this may be more dangerous than you realize. You're effectively tricking OpenJDK into thinking that it has a JAR that comes from somewhere else, which could serve to weaken security or the integrity of your development platform. I mean, after all, if you're going to go place an Oracle JDK JAR into a location, why not just install Oracle JDK outright? – Makoto Dec 17 '17 at 18:54
  • @Makoto The most important thing for me was to find out the reason of the problem. This workaround is also recommended by the "youtrack.jetbrains.com" besides using Oracle JDK. I hope new Debian package of the openjdk would resolve the issue for whom who need openjdk for any reason. – Kayvan Tehrani Dec 18 '17 at 05:36
  • 2
    Wow this is still not fixed. – Gayan Weerakutti Mar 07 '18 at 12:56
4

Use Oracle Java instead of OpenJDK for now. You can pull that in through WebUpd8's repository.

sudo add-apt-repository ppa:webupd8team/java &&
sudo apt-get update &&
sudo apt-get install oracle-java9-installer

It doesn't look like this is going to work with OpenJDK, so if you want to play with the latest and greatest Java, this is going to be the way to do it for now. Otherwise, from what I've seen, you've done this correctly and once this gets actually fixed, it will work just fine.

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • Though this might provide an alternate solution, but yet doesn't answer the real problem here. I would have insisted to make this a comment, yet who knows if OP ends up accepting this way to solve the problem. – Naman Dec 16 '17 at 06:13
  • @nullpointer: I've encountered this issue before on a *different* version of Linux - this one an Ubuntu variant. Ultimately it's frustrating, but the main pain is not being able to use OpenJDK 9 with IntelliJ. The simplest way is to accomplish that with Oracle JDK since it actually *works* with it. The real solution would be, "file a bug with IntelliJ and see what's going on there", since it is mostly on Jetbrains to work out this bug. If the OP wants to use Java 9 though...here's a solution. – Makoto Dec 16 '17 at 07:41
  • As a bounty giver I am not able to change which java version is available at my company, I *might* however be able to add something (a file?) which would make Idea accept this particular version of JDK. I would usually investigate it myself, however I am currently fighting against gradle kotlin dsl.... – mszymborski Dec 16 '17 at 13:42
  • @mszymborski: You should have the power to install software you need on our own machine. If you can't, you are going to want to have a word with your network administrators to be sure that this is possible. – Makoto Dec 16 '17 at 21:36
  • @Makoto - on my own machine - yes I can, but on our servers - no way. This version happens to be the one which was approved. – mszymborski Dec 17 '17 at 12:41
  • @mszymborski: I'm very confused then. It isn't like Oracle Java and OpenJDK are incompatible with each other, and it certainly isn't the case that you're using IntelliJ on your server. This is the least intrusive way to fix the issue until it's fixed upstream, but if you're satisfied with the other approach, then there's not much else to say. – Makoto Dec 17 '17 at 16:46
  • @Makoto: due to relative immaturity of JDK9 we would like to use the very same version on the server as on our laptops (we have a ton of work to do, and having issues due to incompatible versions in the end would be a pretty crapppy icing on the cake). We are currently using another release which works fine with our toolset on our laptops, but when we do actually start tackling our application rather than the surrounding infrastructure and tooling, which we plan on doing starting just after the holidays, we'd rather use the same version everywhere. – mszymborski Dec 17 '17 at 17:44
  • @mszymborski: ...no seriously, Oracle Java and OpenJDK are quite frankly identical. Oracle Java only provides a few extra proprietary binaries that OpenJDK *can't*. Everything else as far as the language and compatibility is concerned is one-for-one. I respect the desire to have a homogeneous stack throughout development, but in all reality, you're not losing anything by using Oracle Java. Again, since you want to go with another workaround which has a higher chance of breaking things than this, I'm really not sure we should continue the conversation. – Makoto Dec 17 '17 at 17:46