Reputation: 123
I installed JDK and set up Maven. Call of mvn -version i get
returns:
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
$JAVA_HOME
variable is set to C:\Program Files\Java\jdk1.8.0_131\bin
in system variables.
Call of %JAVA_HOME%
returns path C:\Program Files\Java\jdk1.8.0_131\bin
.
Where is the problem?
Upvotes: 5
Views: 10263
Reputation: 411
Yes, original question is about pure windows, but for those who came here wondering about windows linux subsystem WSL, I stumbled across the thing trying to set up my win WSL, to use windows java Open jdk binaries. Though in a while i gave up on that idea. Installed jdk with 'sudo apt install ...' and then set WSL java home from installed path:
root@mypc://# java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0+deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
root@mypc://# which java
/usr/bin/java
root@mypc://# realpath /usr/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
use yours realpath instead.
root@mypc://# export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
root@mypc://# mvn -v
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T15:06:16Z)
Maven home: /mnt/c/javaDir/mvn/apache-maven-3.6.2
Java version: 1.8.0_265, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-43-microsoft", arch: "amd64", family: "unix"
add export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 to a ~/.bash_profile for this being set every time linux subsystem is lunched.
Upvotes: 0
Reputation: 18941
The question is about Windows but I came here trying to solve the problem 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
$JAVA_HOME=/home/max/jdk1.8.0_144[[_NO_WHITE_SPACE_AFTER_DECLARATION]]
$JAVA_HOME="/home/max/jdk1.8.0_144"
$JAVA_HOME=/home/max/jdk1.8.0_144/bin
<- This is wrong Upvotes: 2
Reputation: 22233
As you can see in the documentation the JAVA_HOME
variable must point to the java installation path, not to the bin
folder.
Change it to C:\Program Files\Java\jdk1.8.0_131
Upvotes: 14