[java] Error in setting JAVA_HOME

I have recently downloaded Maven and followed the instructions given on this this page. I already have ant installed on my machine. Now, if I want to verify that Maven is installed perfectly or not it is giving me error that JAVA_HOME is not set correctly, but same works perfectly fine for ANT.

For Maven I tried :
1. open cmd
2. type mvn -version
3. Error appeared :
C:\Users\Admin>mvn -version

ERROR: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Program Files\Java\jre7\bin"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation

For ANT I tried and worked :
1. open cmd
2. type mvn -version
3. Apache Ant(TM) version 1.9.1 compiled on May 15 2013

I went to the directory to check that java.exe is actually there in that directory or not and it was there. I checked the environment variables they set fine. I restarted the system and checked again but same problem. Please let me know what am I missing.

This question is related to java maven installation path-variables

The answer is


JAVA_HOME = C:\Program Files\Java\jdk(JDK version number)

Example: C:\Program Files\Java\jdk-10

And then restart you command prompt it works.


The JAVA_HOME should point to the JDK home rather than the JRE home if you are going to be compiling stuff, likewise - I would try and install the JDK in a directory that doesn't include a space. Even if this is not your problem now, it can cause problems in the future!


You are pointing your JAVA_HOME to the JRE which is the Java Runtime Environment. The runtime environment doesn't have a java compiler in its bin folder. You should download the JDK which is the Java Development Kit. Once you've installed that, you can see in your bin folder that there's a file called javac.exe. That's your compiler.


Do not include bin in your JAVA_HOME env variable


Just remember to add quotes into the path if you have a space in your path to java home. C:\Program Files\java\javaxxx\ doesn't work but "C:\Program Files\java\javaxxx\" does.


Follow the instruction in here.

JAVA_HOMEshould be like this

JAVA_HOME=C:\Program Files\Java\jdk1.7.0_07

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to maven

Maven dependencies are failing with a 501 error Why am I getting Unknown error in line 1 of pom.xml? Why am I getting "Received fatal alert: protocol_version" or "peer not authenticated" from Maven Central? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Unable to compile simple Java 10 / Java 11 project with Maven ERROR Source option 1.5 is no longer supported. Use 1.6 or later 'react-scripts' is not recognized as an internal or external command How to create a Java / Maven project that works in Visual Studio Code? "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository Java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException

Examples related to installation

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) Conda version pip install -r requirements.txt --target ./lib How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" PackagesNotFoundError: The following packages are not available from current channels: Tensorflow import error: No module named 'tensorflow' Downgrade npm to an older version Create Setup/MSI installer in Visual Studio 2017 how to install tensorflow on anaconda python 3.6 Application Installation Failed in Android Studio How to install pip for Python 3.6 on Ubuntu 16.10?

Examples related to path-variables

How to set JAVA_HOME in Linux for all users Error in setting JAVA_HOME How to remove entry from $PATH on mac Is there an equivalent of 'which' on the Windows command line?