Windows下Maven安装:“JAVA_HOME设置为无效目录”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24186592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 10:41:04  来源:igfitidea点击:

Maven Installation under Windows: "JAVA_HOME is set to an invalid directory"

javamaven

提问by user2006189

I'm new to Maven and I have downloaded the 3.0.5 version. I'm getting the following error:

我是 Maven 的新手,我已经下载了 3.0.5 版本。我收到以下错误:

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 see no error when I type javacor echo %M2_HOME%in the command prompt.

尽管如此,当我在命令提示符中键入javac或回显时,我没有看到任何错误%M2_HOME%

I have the following path variables set -

我设置了以下路径变量 -

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 someone please help me?

有人可以帮帮我吗?

回答by Sajan Chandran

To set JAVA_HOME

设置JAVA_HOME

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

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

To add mvnto path

添加mvn到路径

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

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

回答by zerocool

JAVA_HOME should be set to jdk installation directory and not to the bin folder.

JAVA_HOME 应该设置为 jdk 安装目录而不是 bin 文件夹。

It should work, once the path is set properly.

一旦路径设置正确,它应该可以工作。

回答by Braj

  • M2_HOMEpoints to the directory where maven is installed.
  • M2points to the bindirectory under maven
  • JAVA_HOMEpoints to the JDK directory installed on your system.
  • M2_HOME指向maven安装目录。
  • M2指向maven下的bin目录
  • JAVA_HOME指向安装在系统上的 JDK 目录。

validate it again from below 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

回答by achingfingers

Read the official documentation. The Maven Installation Instructionsfor Windows are pretty simple to follow.

阅读官方文档。适用于 Windows的Maven 安装说明非常易于遵循。

Windows

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

  • Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.2.1. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.

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

  • Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.

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

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

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

视窗

  • 将分发包解压缩,即 apache-maven-3.2.1-bin.zip 到您希望安装 Maven 3.2.1 的目录。这些说明假设您选择了 C:\Program Files\Apache Software Foundation。子目录 apache-maven-3.2.1 将从存档中创建。

  • 通过打开系统属性(WinKey + Pause),选择“高级”选项卡和“环境变量”按钮添加 M2_HOME 环境变量,然后将 M2_HOME 变量添加到用户变量中,值为 C:\Program Files\ Apache 软件基金会\apache-maven-3.2.1。确保省略路径周围的任何引号,即使它包含空格。注意:对于 Maven 2.0.9,还要确保 M2_HOME 没有“\”作为最后一个字符。

  • 在同一个对话框中,在用户变量中添加 M2 环境变量,其值为 %M2_HOME%\bin。

  • 可选:在同一对话框中,在用户变量中添加 MAVEN_OPTS 环境变量以指定 JVM 属性,例如值 -Xms256m -Xmx512m。此环境变量可用于为 Maven 提供额外选项。

  • 在同一个对话框中,更新/创建用户变量中的 Path 环境变量并在前面添加值 %M2% 以添加命令行中可用的 Maven。

  • 在同一个对话框中,确保 JAVA_HOME 存在于您的用户变量或系统变量中,并将其设置为 JDK 的位置,例如 C:\Program Files\Java\jdk1.7.0_51 和 %JAVA_HOME%\bin位于您的 Path 环境变量中。

  • 打开一个新的命令提示符(Winkey + R 然后键入 cmd)并运行 mvn --version 以验证它是否已正确安装。

回答by AppleBud

Inside your system variables, set JAVA_HOME

在系统变量中,设置 JAVA_HOME

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

and inside path, add these:

在路径内部,添加这些:

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

The error is caused due to non readability of the java path .

该错误是由于 java 路径的不可读性引起的。