Reputation: 305
When I check on maven's version on a virtual environment, I get the following errors:
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
However, I am able to print maven's version outside of virtual environment
mvn -version
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T00:58:13-07:00)
Maven home: /usr/local/Cellar/maven/3.5.2/libexec
Java version: 1.8.0_152, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"
I have used set in ~/.bash_profile
set JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk
set PATH=$JAVA_HOME/jre/bin:$PATH
I don't understand the error as JAVA_HOME is pointing to a JDK and not a JRE? Thanks for answering!
Upvotes: 3
Views: 10729
Reputation: 124648
This is not correct:
set JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk
Notice that the output of mvn
tells you the location of Java home is /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre
.
So the location of the JDK home is probably /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home
.
Secondly, you need to export
the variable, not just set
it.
Write like this:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home
After you update your ~/.bash_profile
,
to test that the setup is correct,
start a new shell, and check the output of echo $JAVA_HOME
.
Upvotes: 6