Introduction
This is an article where the main focus is just to give an alternate solution about how to solve an error message. The error message appear when executing a certain command. That certain command is just a simple maven command. By typing ‘mvn’ command in the command prompt, it will execute the maven tool. It is a tool widely known for building application. For an example for building a Java application. The following is the command execution :
Microsoft Windows [Version 10.0.18363.628] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\Administrator>mvn ERROR: JAVA_HOME not found in your environment. 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 the above error message is very simple. There is a hint in the output of the execution command. That hint is part of the error message. It is informing that the JAVA_HOME is not found in the environment. Moreover, there is an additional hint following after. It is that the JAVA_HOME is actually a variable. Additionally, that JAVA_HOME variable must be exist in the environment which in this case it is the machine as a PC or laptop running using Microsoft Windows. So, how can a JAVA_HOME variable available in it ?. The following are the steps for creating a JAVA_HOME variable to be exist in the environment. In this context, the environment of the PC or laptop running using Microsoft Windows. The steps are in the following order :
-
Just type environment variable at the text field with the ‘Type here to search’ info. In other words, just execute the Windows environment variable settings. It appears as follows :
-
Next, click the Environment Variables button so the following one will appear :
See the JAVA_HOME environment variables in the system variable ?. That is actually the end goal alternative solution for solving the problem. When the error message appear, actually the JAVA_HOME environment variable does not exist in the first place. The image above just as an example showing the image of what the display is going to be. Just click the New… button. Fill the variable name as ‘JAVA_HOME’ and fill the value with the location of the Java installation folder location. In this context, it is ‘C:\jdk-14’.
-
Finally, in the system variables, just edit the Path variable. And the following display will appear :
See the %JAVA_HOME%\bin entry as part of the path ?. The %JAVA_HOME% will refer to the variable as exist in the previous step. In this case, it is ‘C:\jdk-14’. So, the value of ‘%JAVA_HOME%\bin’ will refer to ‘C:\jdk-14\bin’.
-
If it is not working, just place the original path as a new entry. Just add it as follows :
In the above display, at the last empty line, just fill it with the full path of ‘C:\jdk-14\bin’.
-
Last but not least, just run the command once more. If there is no other error message, the following output of the mvn command will exist as follows :
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>
The above ‘mvn -version’ command is actually different with the JDK version above. Well, it is just only a purpose to show that after setting the JAVA_HOME environemnt variable, the maven command is actually working. The following is another example of maven command execution :
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>