简体   繁体   中英

Reconfusing myself over java and compile version

I've been attempting to compile a small java file via javac but have been getting an error 'class file has wrong version 52.0, should be 49.0'

Upon looking this error up, i've found out that this is occuring because I have a different version of Java and a different version of the compiler.

I'm not entirely well-versed on the difference here but I have the following version of Java on my machine:

Java 7u77
Java 8u65
Java 8u66
Java SE Development Kit 8 Update 66
Java 6 Update 38
Java SE Development Kit 6 Update 38

To me, It looks ot me like I have a same version of Java and SDK(8u66) but am not sure why it's causing the failures.

Doing a -version in cmd, I am seeing a similar version:

c:\ServletDevel>java -version
java version "1.5.0_30"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_30-b03)
Java HotSpot(TM) Client VM (build 1.5.0_30-b03, mixed mode)

c:\ServletDevel>javac -version
javac 1.5.0_30
javac: no source files
Usage: javac <options> <source files>

Is there a chance that I'm using an old version of SDK? Or an older version of Java? The plan is to use the Java 8u66 version

Java类版本52是Java8。类版本49是Java5。您收到此错误的原因是,您试图将Java 8类文件与Java 5中的javac一起使用

You are using java 1.5.0_33-bo3.

To use another java you need to update your path pointing to the version of jdk you like most.

Note: If more than one path is pointing to the executables of java the first is taken in to account, so add the path at the beginning, not at the end of existing path.

You have different versions of Java installed in your system and your path seem to be pointed to the oldest version of Java.

What you have to do is, set the path such that it find the latest version of Java. Do the following steps:

  1. Right click on my computer and select Properties
  2. From the left menu choose, Advanced system settings
  3. Once the System settings window opened, then click on "Advanced" tab
  4. Under advanced tab, select the "Environment Variables" button which will open different window
  5. In the other window find out "Path" variable from list of System variables
  6. Click on Path variable and select Edit
  7. Append (do not overwrite or delete content of path variable only append using semi-colon as separator) the location of latest JDK in the path variable.
  8. Click Apply and OK and then close the command prompt and re-open it and check the version of java again.

The path should contain the OLD VALUE appended with something like below (depending on location of your JDK):

C:\Program Files\Java\jdk1.8.0_65\bin

Don't forget to put a semi-color (;) before copy/pasting the path of the latest Java's JDK.

See this question Environment variables for java installation for super clear instructions on how to do this.

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