How to Solve Error Message ERROR: JAVA_HOME is set to an invalid directory when running cmd command to execute maven

Posted on

Introduction

This is another article containing a specific discussion on how to solve an error message. The error message actually exist in the title of this article. It appears when executing a command for running the maven tool. Actually this article has also specific connection with the previous article. That is an article with the title of ‘How to Solve Error Message ERROR: JAVA_HOME not found in your environment when running mvn command to execute maven’. It exist in this link.

So, the error in that article actually has a relation with the error message in this article. In that article, the JAVA_HOME environment is actually not exist. But in this context, it is exist but it is not correct. The error message is giving an information that the JAVA_HOME environment variable has a false value. It points on to an invalid directory. The following is the actual execution of the ‘mvn’ command message :

Microsoft Windows [Version 10.0.18363.628]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>mvn
ERROR: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Program Files\Java\jdk1.8.0_181\bin"
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation
C:\Users\Administrator>

Solution

So, the solution for solving the error message exist above is by changing the value of the JAVA_HOME environment variable’s value. Although the location of the ‘java’ binary program is actually in the ‘bin’ folder which is exist in ‘C:\Program Fiels\Java\jdk1.8.0_181\bin’, it is not the correct value. The correct value is supposed to be just the main root of the Java installation folder. So, the correct value is actually ‘C:\Program Files\Java\jdk.8.0_181’. In order to solve the problem for handling the error message, just execute the following steps :

  1. Just run the environment variable settings. Usually by typing the ‘environment variable’ in the search text field for running a specific part of the program in Microsoft Windows. Actually, below is the appearance of it :

    How to Solve Error Message ERROR: JAVA_HOME is set to an invalid directory when running cmd command to execute maven
    How to Solve Error Message ERROR: JAVA_HOME is set to an invalid directory when running cmd command to execute maven
  2. Following after, just click the Environment Variables button. Next, the display will appear to show the user and system environment variable :

    How to Solve Error Message ERROR: JAVA_HOME is set to an invalid directory when running cmd command to execute maven

    Actually, the above display is already showing the correct answer pattern. Just look at the JAVA_HOME environment variable’s value. As in the image exist, it is ‘C:\jdk-14’.So, it is actually just the root folder of the JAVA installation program. It is not the full path with the ‘bin’ folder where the ‘java’ binary program actually exist. It is only need the Java root folder which in this context it is in ‘C:\Program Files\Java\jdk1.8.0_181’. Just edit the ‘JAVA_HOME’ variable by selecting it and clicking the ‘Edit…’ button. According to the error message, the current value is ‘C:\Program Files\Java\jdk1.8.0_181\bin’. In that case, just change the value to just ‘C:\Program Files\Java\jdk1.8.0_181’.

  3. Finally, just execute the maven command once more. If there are no more error messages available, the following output of the maven command execution will appear :

    Microsoft Windows [Version 10.0.18363.628]
    (c) 2019 Microsoft Corporation. All rights reserved.
    C:\Users\Personal>mvn -version
    Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 20:51:28+0700)
    Maven home: C:\netbeans-8.2\java\maven\bin\..
    Java version: 1.8.0_181, vendor: Oracle Corporation
    Java home: C:\Program Files\Java\jdk1.8.0_181\jre
    Default locale: en_ID, platform encoding: Cp1252
    OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
    C:\Users\Personal>
    

    Another output of the other maven pattern command :

    C:\Users\Personal>mvn
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.115s
    [INFO] Finished at: Sat Feb 12 10:17:33 ICT 2022
    [INFO] Final Memory: 6M/123M
    [INFO] ------------------------------------------------------------------------
    [ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
    C:\Users\Personal>
    

Leave a Reply