java -version and javac -version showing different versions

后端 未结 9 1850
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 01:29

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

9条回答
  •  隐瞒了意图╮
    2020-12-03 01:50

    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.

    Changing the java running

    Try 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.

    Changing the javac running

    If 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.

提交回复
热议问题