有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Windows下的java Maven安装:“java_HOME设置为无效目录”

我是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

不过,在命令提示符中键入javac或echo %M2_HOME%时,我没有看到任何错误

我设置了以下路径变量-

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;

谁能帮帮我吗


共 (5) 个答案

  1. # 1 楼答案

    阅读官方文件。Windows的Maven Installation Instructions操作非常简单

    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.

  2. # 2 楼答案

    将JAVA_设置为主页

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

    mvn添加到路径

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

  3. # 3 楼答案

    在系统变量中,将JAVA_设置为HOME

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

    在path中,添加以下内容:

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

    该错误是由于java路径的不可读性造成的

  4. # 4 楼答案

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

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

  5. # 5 楼答案

    • M2_HOME指向安装maven的目录
    • M2指向maven下的bin目录
    • JAVA_HOME指向系统上安装的JDK目录

    从以下设置再次验证:

    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