0

I am taking a spring boot course and am up to a stage where the program is being run from the command window. I thought I had downloaded maven correctly but if I type mvn package I get:

'mvm' is not recognized as an internal or external command, operable program or batch file.

mvnw package: JAVA_HOME = "C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe" Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

mvnw -version gives the same message as above and mvn -version gives: The JAVA_HOME environment variable is not defined correctly, this environment variable is needed to run this program.

I have set the JAVA_HOME and MAVEN_HOME path as shown in the screenshot but it is still not working. https://i.stack.imgur.com/TFvWn.png https://i.stack.imgur.com/Gk3RF.png

When I type echo %JAVA_HOME% into cmd I get: C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath\\java.exe

and when I change the JAVA_HOME path to that I get the same result.

I have added the path extensions as shown in the image below https://i.stack.imgur.com/AZfUj.png

If anyone can help that would be very much appreciated!

Patrick
  • 1
  • 1
  • The environment variable `JAVA_HOME` should have the absolute path to the java installation, most probably `C:\Program Files (x86)\Common Files\Oracle\Java` in the given case. – Turing85 Apr 02 '23 at 04:00
  • When I change JAVA_HOME to `C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe` I get the same result – Patrick Apr 02 '23 at 04:17
  • You should set it to the **directory** of the Java installation, not to an executable like `java.exe`. The suggestion by Turing85 is wrong, because `C:\Program Files (x86)\Common Files\Oracle\Java` is not a Java installation, it is only a collection of files which will look up the "current" Java installation themselves using the registry (and only for Oracle Java). – Mark Rotteveel Apr 02 '23 at 07:59
  • In other words, find out where your Java is really installed, and set it to that **directory**. For example, I use Eclipse Adoptium, so the correct directory is `C:\Program Files\Eclipse Adoptium\jdk-17.0.6.10-hotspot`. I believe Oracle installs into `C:\Program Files\Java\jdk-`, but it has been a few years since I used an Oracle Java installer, so I might be wrong. – Mark Rotteveel Apr 02 '23 at 08:05
  • Hi Mark, thanks for your input. I have set my directory to `C:\Program Files\Java\jdk-17.0.5`, which I believe is what you're saying but I'm getting the same result. `Error: JAVA_HOME is set to an invalid directory. JAVA_HOME = "C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe" Please set the JAVA_HOME variable in your environment to match the location of your Java installation.` Is there a reason the `JAVA_HOME` isn't changing when I change the directory in my environment variables? – Patrick Apr 02 '23 at 08:22

3 Answers3

0

I found the issue, so if future people come into the same problem as me I had to delete

C:\ProgramData\Oracle\Java\javapath

C:\Program Files (x86)\Common Files\Oracle\Java\javapath

From the Path and have no Java-related entries in the User variables.

Hope this helps!

AlexK
  • 2,855
  • 9
  • 16
  • 27
Patrick
  • 1
  • 1
-1

Ubuntu 22 setup from terminal.

This setup for java 8. Same setup command for higher version.

Setup $JAVA_HOME Environment:

Step 1 :

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Step 2 :

echo $JAVA_HOME

OR :

Step 1 :

sudo nano /etc/environment  

Step 2 :

Paste this line on nano text editor

JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

To save this press ctrl+O and then press ctrl+X

Step 3 :

source /etc/environment 

Step 4 :

echo $JAVA_HOME
Harsh
  • 812
  • 1
  • 10
  • 23
-2

JAVA_HOME path must point to Java bin directory something like C:\Program Files\Java\jdk-....\bin. dots are for your current java version.

  • 2
    JAVA_HOME should not point to the `bin` directory of the Java installation, it should point to the directory above that (the one which contains the `bin` directory). – Mark Rotteveel Apr 02 '23 at 08:00
  • Mark Rotteveel you are right. I messed up JAVA_HOME and PATH. My mistake. – Bozhilov Apr 02 '23 at 09:37