简体   繁体   中英

IntelliJ IDEA - Maven Can't Find JAVA_HOME After Java 11 Install

I'm running IntelliJ IDEA on Ubuntu 18.04. I've just installed Java 11 and have updated my .bashsrc file to set JAVA_HOME to the new JDK. In the terminal I can run mvn clean install and it will build my d fine. But in the IntelliJ terminal window, I get the following error when running a mvn clean install

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

In the IntelliJ terminal window this is the result of echo $JAVA_HOME

/usr/lib/jvm/java-11

Similarly, this is the result of echo $PATH

/home/myusername/.local/bin:/home/myusername/.local/bin:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:
/usr/local/games:/snap/bin:/usr/lib/jvm/java-11/bin:
/usr/lib/jvm/java-11/db/bin:/usr/lib/jvm/java-11/bin:/usr/lib/jvm/java-11/db/bin

What do I need to do to have IntelliJ's version of maven recognize JAVA_HOME ? I've already set my Project SDK to JDK11.

I messed around with this for a couple of hours yesterday but was unable to resolve the issue. In the end, I completely uninstalled both Java and Maven and then reinstalled JDK8 and the latest Maven. This appeared to fix the problem in that IntelliJ's command line was able to locate JAVA_HOME.

Here are the two resources I used to uninstall all Java and then reinstall JDK8, for anyone who is interested.

How to completely uninstall Java

How to install JDK on Ubuntu

I've yet to reinstall JDK11.

I had almost the same issue, except my Java version was shown as 1.8 after typing mvn -v in IDEA, but JAVA_HOME value was empty while it displayed correctly in Linux terminal. I`ve typed the following command in IDEA terminal

export JAVA_HOME=*path to Java 11*

This solved my problem. I think you could try the same without reinstall both Java and Maven.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM