Pages

Monday, August 17, 2015

Setting up JAVA_HOME path for maven in Windows

Go to My computer-> select Properties->select Advanced->Select Environmental Variables(IN Winxp)
In Windows 7 or higher , you can go to environmental variables just by typing environmental variables in search bar.

If you want to set  JAVA_HOME for all the users select NEW in SYSTEM VARIABLES, if you want to set for the current user go and select NEW in user variables for...
Type  JAVA_HOME in Variable name and type the Java directory installation path in Variable value
Have a look at the pics................
JAVA_HOME
You can add any new environmental variable by clicking on NEW button. if you want to append any path to existing env variable just append semi-colon(;) and the path you want to enter to the end of the "variable value".
Example:
Variable name: JAVA_HOME
Variable value: K:\Program Files\Java\jdk1.7.0_0
in future if i want to add some other path like K:\abcd  to the JAVA_HOME, the value becomes
Variable value: K:\Program Files\Java\jdk1.7.0_0;K:\abcd

How to solve JAVA_HOME directory error in maven
http://technocookies.blogspot.com/2015/08/maven-javahome-set-to-invalid-directory.html

About Environmental Variables:

Maven JAVA_HOME set to invalid directory error in Windows

Solution to maven Error: JAVA_HOME is set to an invalid directory.
It's easy to resolve this.... all you have to do is enter the java installation  directory path correctly(don't include bin and don't include any slashes at the end of the path).
(At the time of writing this article i am using apache-maven-3.3.3)
Want to know how to resolve this..........I will explain you how to resolve this.
1.Go to the unzipped directory of maven-> then go to bin directory
Maven bin directory

2.you will find a batch file named "mvn" in the bin directory
3.Open the batch file in notepad or any text editor
4.Have a look at the code that is selected in the pic.


 5.Usually we will include "bin" folder", but to use maven there is no need of  including the bin directory of java in the path.
6.All you need to do is just enter the java installation directory.
7.Here in my system it is installed in "K:\Program Files\Java\jdk1.7.0_07" (no need of including the "bin" folder)


8.There is no need of including any slash at the end.........

You can verify the path you eneterd is correct or not.
as you can see in the code(mvn batch file)
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto chkMHome

%JAVA_HOME% -> just gives the path of the installation directory
/,bin ,java.exe ...everything are there itself in the code.
 so if you run the command in cmd " echo %JAVA_HOME%\bin\java.exe" (don't include quotes) then you can know if there is anything wrong in the path(it has to show the correct path). If it shows correctly then path entered in JAVA_HOME is correct

You can test in command line (cmd) whether the java_home path points to  correct Java installation directory or not
look at the pic below...........
(you can see any value of the environment variable using echo command in cmd)




Note: once if you change any environment variable in windows, please make sure not to check it in the existing opening window of cmd. Open a new cmd(command prompt window) and check the environment variable.
Command to see the value of any environment variable is echo <environmental variable>
example: echo %JAVA_HOME%
              echo %path%