简体   繁体   中英

Java compiler version and java version is different

I am trying to run a compiled java class and getting errors but when I checked my java environments it points to different version.

Javac –version gives me 1.8.0

And

Java –version gives me 1.6.2

The Java_home and path is pointing to the 1.8 version.

Please help.

Java installation under Windows is sometimes a really severe source of pain. The following assumes that you have Windows:

  1. Check your path variable
  2. Check JAVA_HOME variable
  3. Newer versions of Java (1.6 ?, but 1.7 and 1.8) copy some Java executables into the System32 directory of the windows installation. Simply delete this files (or move them somewhere else for easy recovery)
  4. running java applications by using .bat files a specific JDK / JRE can be provided.

There may be more sources of your problem. For example with Maven you depend on JAVA_HOME, with Eclipse you have the project settings, ...

java.exe while java installation gets copied under System32 directory. Also we tend to append java path in the end of the path variable. This causes running java command pointing to the one in System32 (it takes the first path value that is encountered and ignores rest, in this case java of system32 folder). And when it cannot find javac it looks to other values of path and finds it towards the end for the java JDK (this is the one you want to use).To overcome this problem give path to your JDK for example C:\\ProgramData\\Oracle\\Java\\bin as the first entry in the windows path variables. Even before your system32 entry. This ensures you point to only one java. My path entry looks something like this:-

%JAVA_HOME%\bin;%SystemRoot%\system32;

Please check the following :

1) Check your path variable

2) Check JAVA_HOME variable

3)Delete the java,javaw and javaws .exe file from the system32 folder

If you are running Windows, you could perhaps check the path environment variable. It might point to an older JRE installation.

One possibility is that your Java link is inconsistent. Go to this location (Windows):

C:\\ProgramData\\Oracle\\Java\\javapath and check where to does java.exe point.

In case it is not up-to-date consider fixing it with:

mklink /d C:\ProgramData\Oracle\Java\javapath "C:\Program Files\Java\<your JDK>\bin\"

(you may need to remove javapath old link before you create a new one)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM