I was playing around with some environmental variables in Ubuntu 18.04.5, trying to make them not reset every time I re-open terminal.
However, now Maven is reacting to every command with this error:
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
I'm pretty sure that my $JAVA_HOME points to the right directory, because command echo $JAVA_HOME returns:
/usr/lib/jvm/java-11-openjdk-amd64
And command $JAVA_HOME/bin/java --version returns:
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)
Before this error, I've added this lines to /etc/environment:
export JAVA14="/usr/lib/jvm/jdk-14"
export JAVA11="/usr/lib/jvm/java-11-openjdk-amd64"
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
And following lines to ~/.bashrc:
source /etc/environment
Also, after some editing I've returned everything as it was before and command sudo update-alternatives --config java return the following:
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64 1 manual mode
2 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
So the right path is selected, and also I have not changed any other update-alternatives configurations.
What can I do to make Maven see $JAVA_HOME again?
EDIT:
I've fixed this issue by directly editing the /usr/share/maven/bin/mvn script and hard-coding path to java executable into JAVACMD variable. However, I'm still interested in normal solution to this problem.