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

后端 未结 19 1046
误落风尘
误落风尘 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:21

    when you setup the java home variable try to target path till JDK instead of java. setup path like: C:\Program Files\Java\jdk1.8.0_231

    if you make path like C:\Program Files\Java it will run java but it will not run maven.

    0 讨论(0)
  • 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"
    
    0 讨论(0)
  • 2021-02-01 02:23

    removing JAVA_HOME and JAVA_JRE from environment variable is resolved the issue.

    0 讨论(0)
  • 2021-02-01 02:24

    I was having this same issue while my JAVA_HOME system variable was pointing to C:\Program Files\Java\jdk1.8.0_171\bin and my PATH entry consisted of just %JAVA_HOME%.

    I changed my JAVA_HOME variable to exclude the bin folder (C:\Program Files\Java\jdk1.8.0_171), and added the bin folder to the system PATH variable: %JAVA_HOME%\bin,

    0 讨论(0)
  • 2021-02-01 02:24

    I was facing the same issue while using mvn clean package command in Windows OS

    C:\eclipse_workspace\my-sparkapp>mvn clean package
    The JAVA_HOME environment variable is not defined correctly
    This environment variable is needed to run this program
    NB: JAVA_HOME should point to a JDK not a JRE
    

    I resolved this issue by deleting JAVA_HOME environment variables from User Variables / System Variables then restart the laptop, then set JAVA_HOME environment variable again.

    Hope it will help you.

    0 讨论(0)
  • 2021-02-01 02:25

    Setting JAVA_HOME directory from command line worked for me!

    First:

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

    Or :

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

    Then try:

    mvn -version
    

    to make sure you do not get the same error. :)

    0 讨论(0)
提交回复
热议问题