mvn --version不工作?

时间:2014-03-06 11:15:22

标签: java maven-3

我对MAVEN路径​​有疑问 我已经设置了所有路径,但没有工作,请参阅下面的路径

路径

....;C:\Program Files\Java\jdk1.6.0_20\bin;D:\apache-maven-3.2.1\bin

JAVA_HOME

C:\Program Files\Java\jdk1.6.0_20

MAVEN_HOME

D:\apache-maven-3.2.1

当我尝试运行mvn --version时,它会给出JAVA_HOME的错误,请看错误

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

但javac工作正常

5 个答案:

答案 0 :(得分:3)

JAVA_HOME需要指向包含bin/lib/等的文件夹。

您的变量指向

中Java主文件夹的

答案 1 :(得分:2)

将JAVA_HOME C:\Program Files\Java\jdk1.6.0_20\bin更改为C:\Program Files\Java\jdk1.6.0_20

PATHJAVA_HOME是两回事:

使用PATH告诉系统搜索命令的位置。你应该有

PATH=...;C:\Program Files\Java\jdk1.6.0_20\bin;

使用JAVA_HOME定义Java的安装位置。使用JAVA_HOME的应用程序添加bin和/或lib目录。你应该有

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20

在DOS-Box中尝试以下操作:

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20
set MAVEN_HOME=D:\apache-maven-3.2.1
set PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin
mvn --version

答案 2 :(得分:0)

确定JRE安装路径后:

Right-click the My Computer icon on your desktop and select Properties.
Click the Advanced tab.
Click the Environment Variables button.
Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.

    If your Java installation directory has a space in its path name, you should use the shortened path name (e.g. C:\Progra~1\Java\jre6) in the environment variable instead.
    Icon

    Note for Windows users on 64-bit systems

    Progra~1 = 'Program Files'
    Progra~2 = 'Program Files(x86)'
Click OK.
Click Apply Changes.
Close any command window which was open before you made these changes, and open a new command window. There is no way to reload environment variables from an active command prompt. If the changes do not take effect even after reopening the command window, restart Windows.
If you are running the Confluence EAR/WAR distribution, rather than the regular Confluence distribution, you may need to restart your application server.

答案 3 :(得分:0)

您需要设置或确保3个变量的环境行为: 1. M2_HOME:设置此环境变量以指向apache maven目录。注意:一定不要指向bin目录。

  1. JAVA_HOME:此环境变量必须指向jdk文件夹,不包括bin目录。

  2. 路径:您的系统/用户路径变量必须指向java环境的bin目录。

  3. 这对我来说很好。

答案 4 :(得分:-1)

首先设置所有这些东西

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20
set MAVEN_HOME=D:\apache-maven-3.2.1
set PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin

检查

mvn --version
  

如果仍然无法正常运行,请再次删除环境变量中的路径,将其创建为

PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin

关闭先前打开的cmd提示

open new cmd

并检查

mvn --version