I have java 7
and java 8
both installed on my windows system under C:\\Program Files\\Java
In the environment\'s path I specif
Check your JAVA_HOME variable under environment variables in Windows machine. Make sure It is pointing to the version that you want. Next check java jdk path added into your "path" environment variable. Make sure It is the version that you want, Otherwise change this to your JDK version path and then move this to the top of the list of values in path variable. This should mark your desired version as the first choice and all issues will be resolved. I did so, and everything is good.
To resolve such kind of environment issue I always believe on command whereis, To do the same in windows download whereis.exe then set in path and execute the command
whereis java.exe
whereis javac.exe
You will easily find the exact path from which location java is being called in environment as well about javac.
Yes, it is true that in order to deal with mismatching versions we need to modify the PATH variable, and the where
command (at least, in Windows) is very handy in finding out which program gets picked first.
There's, however, a twist:
when you look at the contents of yout PATH var after running, for example,
echo %path% > path.txt
you should be aware of the fact that PATH is actually composed of TWO sections: one is System PATH and the other is Current User PATH, and it is System Path that gets evaluated first but printed last. So simply placing a path to your, say, brand-new JDK in front of everything will be useless as long as there's another place with older version somewhere in the System PATH.
This particular problem is especially common when you have entries such as
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath
in your System PATH. Simply move them to the tail of your Current User PATH section to make these entries the last ones within the search queue.
Go to Environment Variables in your windows machine. In User Variables : Make sure to set - Your user variable "JAVA_HOME" value to "C:\Program Files\Java\jdk-xxxx\bin" where "jdk-xxx" is the version of your jdk.
In System Variable : - Add same "C:\Program Files\Java\jdk-xxxx\bin" value to "Path" variable. make sure to move the added value on top of all values.
Now try running java -version and javac -version. worked for me. :) Here i've linked my screenshot
My case (moving jdk8 -> jdk9 -> jdk11) I had a garbage left by jdk8 in PATH (before JAVA_HOME:"C:\path\java11")
so I just remove C:\ProgramData\Oracle\Java\javapath_jdk8
from system variables
// or place it below javapath_jdk11
Ok, as you said that you have no JRE on your path, I assume that where java (if you have Windows 7) will give you C:\Windows\System32\java.exe
.
java
runningTry using the Java-Settings Dialog from the control panel to change the Java System Version, which is currently active. This should change the version java -version
is returning. If this does not work, you will probably need to reinstall the Java version of which you want to run the java
command, specify the path explicitly, write you own wrapper (which works if you are in the same directory as the wrapper) or place the JRE path before C:\Windows\System32\
onto your path (don't know if last option really is a good one).
A wrapper could look just like this:
@"C:\Program Files\Java\jre7\bin\java.exe" %*
and you can either name it java.bat
(where it will work if you are in the same directory or put it in PATH
before C:\Windows\System32\java.exe
or you could name it java7.bat
and put it anywhere on you path to be able to run the Java 7 JRE if you desire to do so.
A wrapper is also a good option if you want to change the JAVA_HOME
when running.
javac
runningIf you want to run a different javac
hit Windows + Pause
and open the system dialog to change the PATH
so it contains the path to your JDK 8 instead of your JDK 7. You will need to restart your command line for changes to show.