Install Maven on Windows: "JAVA_HOME is installed in an invalid directory"

I am new to Maven and I downloaded version 3.0.5. I get the following error:

JAVA_HOME is set to an invalid directory. please set the java_home variable in your environment variable to match the location of your java installation 

Although I do not see an error when entering javac or echo %M2_HOME% on the command line.

I have the following path variables -

 CLASSPATH - ;C:\Program Files (x86)\Java\jdk1.7.0_40\lib; JAVA_HOME - C:\Program Files (x86)\Java\jdk1.7.0_40\bin M2 - %M2_HOME%\bin M2_HOME - C:\Users\cbil\Documents\Maven\apache-maven-3.0.5-bin\apache-maven-3.0.5 MAVEN_OPTS - -Xms256m -Xmx512m PATH - C:\Program Files\Java\jdk1.7.0_45\bin;C:\Users\cbil\Documents\Maven\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin; 

Can anyone help me out?

+6
source share
5 answers
  • M2_HOME points to the directory where maven is installed.
  • M2 points to bin directory in maven
  • JAVA_HOME points to the JDK directory installed on your system.

confirm it again from the following settings:

 JAVA_HOME - C:\Program Files\Java\jdk1.6.0_23 M2_HOME - D:\Software\apache-maven-3.0.5 M2 - %M2_HOME%\bin PATH - %M2%;%JAVA_HOME%\bin 
+15
source

JAVA_HOME should be installed in the jdk installation directory, and not in the bin folder.

It should work as soon as the path is set correctly.

+3
source

Inside system variables, set JAVA_HOME

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

and inside the path add the following:

  C:\maven\bin;%JAVA_HOME%\bin; 

The error is caused by the unreadability of the Java path.

+3
source

Read the official documentation. The installation instructions for Maven for Windows are pretty simple.

Window

  • Unzip the distribution archive, i.e. apache-maven-3.2.1-bin.zip, to the directory you want to install Maven 3.2.1. These instructions assume you selected the C: \ Program Files \ Apache Software Foundation. The apache-maven-3.2.1 subdirectory will be created from the archive.

  • Add the M2_HOME environment variable by opening the system properties (WinKey + Pause), selecting the "Advanced" and "Environment Variables" tabs, and then adding the M2_HOME variable to user variables with the value C: \ Program Files \ Apache Software Foundation \ Apache-Maven- 3.2.1. Be sure to omit the quotation marks around the path, even if it contains spaces. Note. For Maven 2.0.9, also make sure that M2_HOME does not have "\" as the last character.

  • In the same dialog box, add the M2 environment variable to user variables with the value% M2_HOME% \ bin.

  • Optional: in the same dialog box, add the MAVEN_OPTS environment variable in the user variables to specify the JVM property, for example. value -Xms256m -Xmx512m. This environment variable can be used to provide additional Maven options.

  • In the same dialog, update / create the Path environment variable in the user variables and add the value% M2% to add Maven to the command line.

  • In the same dialog box, make sure that JAVA_HOME exists in your user variables or system variables and that it is set to the location of your JDK, for example. C: \ Program Files \ Java \ jdk1.7.0_51 and that% JAVA_HOME% \ bin is in the Path environment variable.

  • Open a new command prompt (Winkey + R, then type cmd) and run mvn -version to make sure it is installed correctly.

+2
source

To set JAVA_HOME

set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_40

To add mvn to the path

set PATH=%PATH%;C:\Users\cbil\Documents\Maven\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin;

+1
source

Source: https://habr.com/ru/post/970756/


All Articles