How do I fix maven error The JAVA_HOME environment variable is not defined correctly?

后端 未结 19 1118
误落风尘
误落风尘 2021-02-01 01:33

Issue:

I am getting the Maven error \"The JAVA_HOME environment variable is not defined correctly\" when I run through Inno setup batch execution. Howe

19条回答
  •  攒了一身酷
    2021-02-01 02:23

    This is how I fixed this issue on Windows 10:

    My JDK is located in C:\Program Files\Java\jdk-11.0.2 and the problem I had was the space in Program Files. If I set JAVA_HOME using set JAVA_HOME="C:\Program Files\Java\jdk-11.0.2" then Maven had an issue with the double quotes:

    C:\Users>set JAVA_HOME="C:\Program Files\Java\jdk-11.0.2"
    
    C:\Users>echo %JAVA_HOME%
    "C:\Program Files\Java\jdk-11.0.2"
    
    C:\Users>mvn -version
    Files\Java\jdk-11.0.2""=="" was unexpected at this time.
    

    Referring to Program Files as PROGRA~1 didn't help either. The solution is using the PROGRAMFILES variable inside of JAVA_HOME:

    C:\Users>echo %PROGRAMFILES%
    C:\Program Files
    
    C:\Program Files>set JAVA_HOME=%PROGRAMFILES%\Java\jdk-11.0.2
    
    C:\Program Files>echo %JAVA_HOME%
    C:\Program Files\Java\jdk-11.0.2
    
    C:\Program Files>mvn -version
    Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T17:06:16+02:00)
    Maven home: C:\apache-maven-3.6.2\bin\..
    Java version: 11.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11.0.2
    Default locale: en_US, platform encoding: Cp1252
    OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
    

提交回复
热议问题