Reputation: 696
I am trying to change my java version because of compiler errors when running mvn install
via the windows command prompt.
I changed the JAVA_HOME variable and made sure that it is referenced in the PATH variable (##EDIT##: had been done like this %JAVA_HOME%\bin;%PATH%;
).
When I open the command prompt in the folder where my pom.exe is located (using the Windows 7 'Open command window here'
shortcut) and type java -version
the unchanged java version is displayed.
I made sure to close all instances of command prompts before starting a new one.
Strangely I discovered that when starting the command prompt via the Run dialog
in the start menu
(by typing cmd
) the result of java -version
is the desired version.
Upvotes: 5
Views: 31414
Reputation: 1
move you path/to/jdk/bin in your variable env up. (better make it on the top of the list)
Upvotes: 0
Reputation: 1
When you install java, you need to set the path variable. When you add another version of java on top of the existing one, make sure to either - remove the old path or put the new path before the old one.
Upvotes: 0
Reputation: 181
I faced this issue too. I changed the JAVA_HOME in the environment variable and then when I opened cmd and typed java -version
, I've seen older version. Then, I deleted javapath file in C:/Program Files/Common Files/Oracle/Java. My issue has been fixed in this way.
Upvotes: 18
Reputation: 31
In my case worked the following: after editing the environment variables, and checking by command line java -version and javac -version, javac was updated but not java, so you have to do it by command line also set path=C:\Program Files\Java\jdk1.8.0_181\bin
Upvotes: 3
Reputation: 1601
I too faced this problem where I want to change the java version in command prompt but failed. But finally I succeeded doing the below steps. First I'll show the failed attempt, followed by the actual success step so you will know the difference.
Failed Step:
1. Win + R
2. Type cmd
and hit enter
3. Type java -version
(Just to check if the version is the old one which we need to change)
4. Now try changing the path/classpath using set path=/classpath=
5. Now again type java -version
(This will still show the old java version but not the new version which we set)
Success Step:
1. Win + R
2. Type open command window here
and hit enter
3. Type java -version
(Just to check if the version is the old one which we need to change)
4. Now try changing the path/classpath using set path=/classpath=
5. Now again type java -version
and voila I see the changed java version here
Thanks!
Upvotes: 0
Reputation: 696
When using the 'Open command window here'
shortcut make sure to close and open the respective explorer window. When starting the command prompt in this way Windows uses cached environment variables and does therefore not retrieve the current version of java.
Took me a while to figure out because it was too surprising to expect this behavior. Before I was searching on google and stackoverflow.com without any results. Hope this saves someone the trouble.
Upvotes: 5
Reputation: 12401
Remove the existing JRE setups..
Install the one that you need to install. Hope you have added it in the environment variable and path via settings... Test it, it should work!.
The same thing happened to me long ago, It was pointing to the older JRE, got stuck, so removed the existing JDKs and installed a fresh copy. It worked.
Upvotes: 0
Reputation: 37093
You need to modify path variable as well as below:
PATH=%JAVA_HOME%/bin;%PATH%
Post that make sure you open a new command prompt and rerun maven command.
Upvotes: 11