You are not logged in.

#1 2020-10-14 21:50:18

origamisith
Member
Registered: 2020-07-13
Posts: 31

IntelliJ IDEA won't recognize JDK

I have recently installed IntelliJ IDEA and OpenJDK 15. When I try to compile my barebones Java program, it throws the error

 java: Cannot find JDK 'openjdk-15 for module 'myProgram'

. I have made sure that JDK 15 is enabled in the preferences where it should be. I have uninstalled / reinstalled IntelliJ and multiple versions of the JDK. I have invalidated the cache and restarted. What should I do?

Offline

#2 2020-10-15 10:05:52

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: IntelliJ IDEA won't recognize JDK

Latest openjdk version in repos is 14 , I also don't see an openjdk 15 pacakge in AUR .

How did you install openjdk 15 ?

please post output of

$ archlinux-java status

Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#3 2020-10-15 22:40:51

origamisith
Member
Registered: 2020-07-13
Posts: 31

Re: IntelliJ IDEA won't recognize JDK

So when I wrote the question, I was trying 15. Now, I'm trying 14, directly from the AUR. Same problem. I am able to compile and run from the command line, but not with the IntelliJ Build / Run features. Output of

archlinux-java status

is:

Available Java environments:
  java-14-openjdk (default)

Of course, the error message has updated to reflect the different JDK.

java: Cannot find JDK '14' for module 'MyProgram'

According to IntelliJ. the JDK home path for JDK '14' is /usr/lib/jvm/java-14-openjdk, and the classpath tab shows many java.* and  jdk.* files.

Offline

#4 2020-10-17 22:06:19

origamisith
Member
Registered: 2020-07-13
Posts: 31

Re: IntelliJ IDEA won't recognize JDK

This may be a system-wide problem? Because I tried installing LibreOffice, and it says that it can't find the jdk either.

 
Warning: failed to read path from javaldx
LibreOffice 6.4 - Fatal Error: The application cannot be started. 
[context="user"] caught unexpected com.sun.star.ucb.ContentCreationException: Cannot create folder (invalid path): '$HOME'
 

I've installed JDK versions 8,11,14, and 15, but they all give me these kinds of problems for libreoffice and IntelliJ. Also, my $PATH includes /lib/jvm/default, /usr/lib/jvm/default, and /usr/lib/jvm/default/bin

Offline

#5 2020-10-17 23:39:41

solskog
Member
Registered: 2020-09-05
Posts: 407

Re: IntelliJ IDEA won't recognize JDK

I think this is on the IDEA project settings. IDEA-> File -> Project structure -> Project SDK
Try create a simple command line java project with this setting and see if you get same error.

Last edited by solskog (2020-10-18 01:48:23)

Offline

#6 2020-10-18 05:35:33

origamisith
Member
Registered: 2020-07-13
Posts: 31

Re: IntelliJ IDEA won't recognize JDK

I have already done so. Again, I have tried setting the Project SDK to several different versions of the JDK and different paths as well. My program was the simplest Hello World program.

Offline

#7 2020-10-18 08:00:49

solskog
Member
Registered: 2020-09-05
Posts: 407

Re: IntelliJ IDEA won't recognize JDK

How about check your java environment by compile and run a simple Hello World from terminal/urxvt/st/gnome-terminal command line outside IDEA?

$ source /etc/profile.d/jre.sh
$ echo $PATH
$ cat HelloWorld.java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
}
$ javac HelloWorld.java
$ java HelloWorld
...

Or via IDEA Terminal.

$ cat IdeaProjects/HelloWorld/src/com/company/HelloWorld.java
package com.company;
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
$
$ source /etc/profile.d/jre.sh
$ echo $PATH
$ cd IdeaProjects/HelloWorld/src/
$ javac com/company/HelloWorld.java
$ java com/company/HelloWorld
...

What is the error message if any?

Last edited by solskog (2020-10-18 08:13:40)

Offline

#8 2020-10-18 08:44:01

origamisith
Member
Registered: 2020-07-13
Posts: 31

Re: IntelliJ IDEA won't recognize JDK

Oh yes, I forgot to mention. The JDK works when just called with java or javac.JShell works. Also, Eclipse doesn't have any problems.

Offline

#9 2020-10-18 10:06:11

solskog
Member
Registered: 2020-09-05
Posts: 407

Re: IntelliJ IDEA won't recognize JDK

Well then, this must be a IDEA environment issue.

Offline

#10 2020-10-18 16:30:50

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: IntelliJ IDEA won't recognize JDK

origamisith wrote:

Oh yes, I forgot to mention.

Let's slow down here for a minute. I don't think you fully understand how [ extra ]'s jdk-openjdk, AUR versions, archlinux-java, JAVA_HOME and IDEA project settings work together. The very first question that @Lone_Wolf asked is actually the most relevant: *how* did you install openjdk 15? Even if you are now on JDK 14, we need to pause for a sec and get the full story there. That will likely get us to a place where your problem can be fixed.

Offline

#11 2020-10-23 06:15:43

origamisith
Member
Registered: 2020-07-13
Posts: 31

Re: IntelliJ IDEA won't recognize JDK

For openjdk 15: Went to the JDK website and downloaded the tarball from https://jdk.java.net/15/. Once I extracted, I moved it to /lib/jvm, and it appeared in the list of archlinux-java status.
For openjdk 14:

pacman -S jre-openjdk 

. Also tried jre11-openjdk and jre8-openjdk.
When I run

echo $JAVA_HOME

I see nothing, but I thought I didn't need to set that myself.

**Correction** The first time I tried installing openjdk 15 was by getting the "java-openjdk-bin" package from the AUR, with git clone and makepkg -rsi as usual.

Last edited by origamisith (2020-10-23 06:23:39)

Offline

#12 2020-10-23 08:06:03

solskog
Member
Registered: 2020-09-05
Posts: 407

Re: IntelliJ IDEA won't recognize JDK

you are suppose to install jdk not jre for java development.

# pacman -S jdk-openjdk

Offline

#13 2020-11-07 20:17:24

origamisith
Member
Registered: 2020-07-13
Posts: 31

Re: IntelliJ IDEA won't recognize JDK

My mistake. I do have the JDK installed, not the JRE.

Offline

#14 2020-11-08 09:38:25

icar
Member
From: Catalunya
Registered: 2020-07-31
Posts: 442

Re: IntelliJ IDEA won't recognize JDK

Try righ-clicking the project root folder (on the left sidebar) > Properties > Java Build Path > Select the JRE System Library > Edit > Execution environment > Select the one you have installed (or try different ones if you don't know).
You probably need to edit your JRE System Library in your projects settings. Search for Java Build Path or similar.

Last edited by icar (2020-11-08 09:41:39)

Offline

#15 2020-11-09 21:28:12

origamisith
Member
Registered: 2020-07-13
Posts: 31

Re: IntelliJ IDEA won't recognize JDK

Well, I have to give credit to the Intellij forums for this one. I changed the idea.properties file (which was /opt/intellij-idea-ultimate-edition/bin/idea.properties for me) by specifying the idea.config.path to be /home/myuser/.IntelliJIdea/config and the idea.system.path to be /home/myuser/.IntelliJIdea/system. Apparently, IntellIJ couldn't find my home folder, and this fix allowed me to avoid using ${user.home} in the config file.
In fact, a lot of applications have had similar problems. I have to specify the config files manually for i3, polybar,  and picom even though they are in $HOME/.config like they should be. What could cause applications to not see my user home directory?

Last edited by origamisith (2020-11-09 21:30:56)

Offline

#16 2020-11-10 11:21:38

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: IntelliJ IDEA won't recognize JDK


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#17 2020-11-10 14:29:31

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: IntelliJ IDEA won't recognize JDK

origamisith wrote:

What could cause applications to not see my user home directory?

Have you checked the basics: what does

echo $HOME

return?

Offline

Board footer

Powered by FluxBB