为什么我在尝试安装Maven时将Java设置为无效目录?

时间:2014-11-07 15:56:12

标签: java maven

我正在尝试安装Maven以运行selenium junit测试 然后将其集成到Jenkins

当我在CMD中运行时:mvn -version,我有这个:

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

当我运行java -version时,我有这个:

java version "1.8.0_20"
Java(TM) SE Runtime Environment (Build 1.8.0_20-h26)
Java HotSPot(TM) 64-Bit Server VM (build 25.20-h23, mixed mode)

为什么我会收到此错误?


这是我对java和maven的配置

我有Windows 7 64位

  1. 我在这里安装了Maven

    C:\Program Files\Apache Software Foundation\apache-maven-3.2.3
    
  2. 对于java,我安装了这些版本:

    C:\Program Files\Java\jdk1.6.0_37  should i keep this version?
    C:\Program Files\Java\jdk1.7.0_60  should i keep this version?
    C:\Program Files\Java\jdk1.8.0_11  
    C:\Program Files\Java\jre1.8.0_20  
    C:\Program Files\Java\jre6
    C:\Program Files\Java\jre7
    
  3. 在用户变量中,我有:

    JAVA_HOME
    C:\Program Files\Java\jdk1.8.0_11\bin
    
    MAVEN_OPTS
    %M2% 
    
    PATH
    C:\Program Files\Java\jdk1.8.0_11\bin;
    
  4. 系统变量中的
  5. ,我有:

    JAVA_HOME
    C:\Program Files\Java\jdk1.8.0_11\bin
    
    JRE_HOME
    C:\Program Files\Java\jre6;
    
    M2
    %MAVEN_HOME%\bin;
    
    MAVEN_HOME
    C:\Program Files\Apache Software Foundation\apache-maven-3.2.3;
    
    Path
    C:\Program Files\Apache Software Foundation\apache-maven-3.2.3\bin;C:\Program Files\Java\jdk1.8.0_11\bin;
    

4 个答案:

答案 0 :(得分:4)

请在环境中设置JAVA_HOME变量以匹配 Java安装的位置。这显然是说你对JAVA_HOME的价值是错误的。
使用以下值更改您的JAVA_HOME。

JAVA_HOME = "C:\Program Files\Java\jdk1.8.0_11"


PATH和JAVA_HOME是两个不同的环境变量。 JAVA_HOME是java安装目录。 其中PATH for Java是javac.exe的位置,java.exe就像可执行文件一样,所以它高达%JAVA_HOME%bin。

答案 1 :(得分:1)

将JAVA_HOME设置为C:\ Program Files \ Java \ jdk1.8.0_11,不带\ bin 并在路径中放置%JAVA_HOME%\ bin

答案 2 :(得分:1)

请转到http://dbc-customs.com/?p=96

1. Download and install Java JDK (minimum 1.7) Jave SE downloads

2. Download Maven Binary from Apache from the Maven Downloads Page or use this direct link for Maven 3.2.1 (Binary zip)

3. Extract zip file to C:\Program Files (x86)\ApacheMaven\apache-maven-3.2.1 (Note: if you select a different directory, please update following steps accordingly)

4. Open the “Environment Variables” in Windows. (WinKey + Pause/Break) > Advanced System Settings > Advanced tab > “Environment Variables…” Button.

5. Add the following variables to the “System variables” section. (Not the “User variables”)

JAVA_HOME
C:\Program Files\Java\jdk1.7.0_51

M2_HOME
C:\Program Files (x86)\ApacheMaven\apache-maven-3.2.1

M2
%M2_HOME%\bin

6. Open the “Path” variable in the System variables section, and add the following at the end of your Path:
;%M2%;%JAVA_HOME%\bin
Note: the semicolon ( ; ) is used to separate values.

7. Open a new command prompt (Winkey + R then type cmd) and run mvn --version

to verify that it is correctly installed.

C:\Users\curtis>mvn --version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T10:37:52-07:00)
Maven home: C:\Program Files (x86)\ApacheMaven\apache-maven-3.2.1
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_51\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

答案 3 :(得分:0)

您的配置应该是:

JAVA_HOME = C:\Program Files\Java\jdk1.8.0_11
M2_HOME = C:\Program Files\Apache Software Foundation\apache-maven-3.2.3

然后在路径中添加:

;%JAVA_HOME%\bin;%M2_HOME%\bin

如果您需要解释,请查看:

For Java

For Maven