Ubuntu maven The JAVA_HOME environment variable is not defined correctly - maven

I installed maven in Ubuntu 22.04 and I am getting the next error when I try a mvn clean install command:
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
My JAVA_HOME has the next value:
echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64/bin/
Am I missing something?
Thanks!

JAVA_HOME needs to be one level up - /usr/lib/jvm/java-11-openjdk-amd64

Related

Java_home path cannot be set

I am using linux subsystem with Debian 10. I installed Java 17 and set the Java homepath to jdk 17.
The JAVA_HOME Path ist still java-11, but this isnt even installed.
echo %JAVA_HOME% set set JAVA_HOME=/usr/lib/jvm/java-17-oracle echo %JAVA_HOME%
%JAVA_HOME% set set JAVA_HOME=/usr/lib/jvm/java-17-oracle echo %JAVA_HOME%
I tried to change the home variable permanently, but it does not work.
Well? Still exception
Downloaded java versions
installed java version
How can i change the Java_Home path permanently.
Thank you in advance
If you install JAVA through your distro's default package manager(for example I use Ubuntu so I install Java(the OpenJDK version of Java) through APT [so the command to install OpenJDK's Java17 for example is sudo apt install openjdk-17-jdk]). Regardless of the version you install via APT, Java will be installed in the /usr/lib/jvm/{java-version-distribution-architecture} path. So, the easiest way to set the JAVA_HOME variable is to edit your .bashrc file and add this inside it using your text editor:
JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export JAVA_HOME
PATH=$PATH:JAVA_HOME/bin
export PATH
Save and close the file after adding this information inside it. Then run the command source .bashrc(to stamp you changes) and the JAVA_HOME will be permanently set. Also note that the .bashrc file is located in the ~/.bashrc(your home). You can confirm the JAVA_HOME variable by using the command echo $JAVA_HOME on the terminal and it should show you the path you just set. I hope this helps

upon checking mvn version this massage pop up on Mac please need help to resolve this issue

mvn -version
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.

Maven cannot identify JAVA_HOME on macOS 11.6.7

I am on macOS 11.6.7. My JAVA_HOME variable is set to ~/.zshenv as:
export JAVA_HOME=$(/usr/libexec/java_home)
My terminal output for both echo $JAVA_HOME and mvn --version are as follows:
<redacted> ~ % echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home
<redacted>~ % mvn --version
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.
I have attempted to source ~/.zshenv as well as restarting shell. The JAVA_HOME variable is read correctly even still. What am I missing? Are there other configuration files I have to check/set for Maven specifically?

macbook 10.15.5 install maven failed: NB: JAVA_HOME should point to a JDK not a JRE

I know there are a lot of questions/answers about this question, but all were failed in my case.
I installed jdk 1.8 and then installed maven3.6.3, java runs well but mvn command didn't work, see my command output and env:
java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
mvn -v
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
mac OS version: 10.15.5
echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
echo $PATH
/usr/local/apache-maven-3.6.3/bin:/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:.
config in ~/.bash_profile
export M2_HOME=/usr/local/apache-maven-3.6.3
PATH=$M2_HOME/bin:$JAVA_HOME/bin:$PATH:.
#Mac OSX 10.15.5 or later version need this configure
export JAVA_HOME=$(/usr/libexec/java_home)
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export PATH
I also source ~./bash_profile to make configure effective.
I would suggest revert all the changes you have made in ~/.bash_profile. Checkout my way to make the maven work:
Download latest maven zip package apache-maven-<version>-bin.zip from Apache maven download page.
Unzip it to any place, e.g: ~/Develop/apache-maven-3.6.0
Create a link with command sudo ln -sf ~/Develop/apache-maven-3.6.0/bin/mvn /usr/local/bin/mvn (change version number per your case, if the local bin folder missing, just create it mkdir -p /usr/local/bin).
Check the installation mvn --version
Hope it works for you.
After hundreds updating configure file, now mvn -version can works, share my update and hope it can help you.
fill or update vim ~/.mavenrc(in the beginning, this file isn't exist)
# my MacOS is 10.15+
export Java_HOME=$(/usr/libexec/Java_home)
and then source ~/.mavenrc to let system env effective.
Summary:for my mac system, seems maven couldn't get JAVA_HOME from .bash_profile or .profile, so if you confirm your JAVA_HOME is set correctly and MAVEN_HOME configured, then you can have a try in this way.

JAVA_HOME is not working in maven

java is installed at this path
$ which java
/usr/bin/java
mvn -version is giving this error
$ mvn -version
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 have tried some of the solutions that were available online, but those don't work for me. Some of those solutions suggested adding
$export JAVA_HOME = /usr/libexec/java_home
or
$export JAVA_HOME = $(/usr/libexec/java_home)
to below files
~/.bashrc
~/.bash_profile
~/.profile
Also when I try to execute one shell command, it shows me error like
Error: JAVA_HOME is not defined correctly.
CARBON cannot execute /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java
After struggling for almost a day, I found out that maven is not reading the $JAVA_HOME from either of
~/.bashrc
~/.bash_profile
~/.profile
but it reads $JAVA_HOME from ~/.mavenrc
So finally, when I added
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home
in ~/.mavenrc then got output
mvn -v
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1024m; support was removed in 8.0
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T15:39:06-04:00)
Maven home: /usr/local/Cellar/maven/3.5.0/libexec
Java version: 1.8.0_141, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre
Default locale: en_CA, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"
To fixed it, update the JAVA_HOME like following :
$ vim .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
$ source .bash_profile
Run Maven again :
$ mvn -version
maven reads JAVA_HOME from ~/.mavenrc. Add path for JAVA_HOME to ~./mavenrc and source it.
$ vim ~/.mavenrc
export JAVA_HOME=$(/usr/libexec/java_home)
$ source .mavenrc
On Ubuntu
I faced a similar problem. I configured $JAVA_HOME in /etc/environment
like JAVA_HOME=PATH_TO_JDK for example JAVA_HOME=/home/max/jdk1.8.0_144
Careful with
White space after path declaration JAVA_HOME=/home/max/jdk1.8.0_144[[_NO_WHITE_SPACE_AFTER_DECLARATION]]
Don't put any quotes, e.g. JAVA_HOME="/home/max/jdk1.8.0_144"
Don't put /bin, e.g. JAVA_HOME=/home/max/jdk1.8.0_144/bin <- This is wrong
Please check once there should be no ';' in JAVA_HOME value, if there is semicolon then it would show above error.
I had
JAVA_HOME
set but did not export it and maven was not picking up the correct JAVA_HOME.
Once I exported JAVA_HOME then it got resolved. Do not forget to export JAVA_HOME so that the variable is available to child processes (UNIX* like OS)
export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home

Resources