Unsupported major.minor version 50.0

来源:互联网 发布:周扬青淘宝店 卖什么 编辑:程序博客网 时间:2024/05/22 15:11

以下摘自Oracle

****************************************************************************************************************************************

Symptoms

error    java.lang.UnsupportedClassVersionError:  ...Unsupported major.minorversion 50.0

Cause

The exception "Unsupported major.minor version <yy>.0" is raised when the run-time Java release is a lower than the Java release used to compile the class.

For example a class compiled using Java 6 (major.minor = 50.0) can not be run with Java 5 (major.minor = 49.0) or Java 1.4.2 (major.minor = 48.0) and thus raises

Unsupported major.minor version 50.0

Note that no exception is raised when class is compiled with Java 5 (major.minor = 49.0) and then run with Java 6 (major.minor = 50.0). It's fine to run the class with a newer Java version than it was compiled with.

Solution

To resolve the error the class needs to be compiled using the same or lower Java release as used on run-time. There are 2 options to accomplish this

  1. Compile the class with the same (or older) Java version as used on run-time
  2. Compile the class and use the parameters -source and -target to mimic class is compiled with lower version. 

For example when having Java 6 running compilation as 

# javac -source 1.5 -target 1.5 myclass.java

makes that the both source (.java) and target (.class) are interpreted as Java 5 and class will reference major.minor = 49.0 (see below table)

 Hints and tips:

  • Ensure that the javac and java executable are used from the same JDK_HOME.

Run # which javac and # which java to confirm.

The environment setting PATH may resolve java from $IAS_ORACLE_HOME/appsutil/jdk/jre/bin, while thejavac is located in $IAS_ORACLE_HOME/appsutil/jdk/bin. This causes that the javac is taken from another JDK_HOME which may have a different (and possible newer) Java version.  To prevent this add the $IAS_ORACLE_HOME/appsutil/jdk/bin at the start of the PATH settin, so javac is used from the correct JDK_HOME

  • To verify the version class is compiled use the javap utility coming with the JDK ( it's not included with the JRE only installation)

Run # javap -verbose <class> | grep version 

note: provide the name without extenstion, so use myclass instead of myclass.class

Check the major version collected in below table

Major versionJava46Java 1.247Java 1.348Java 1.449Java 550Java 651Java 7

 

 

 

 

 

 

 

******************************************************************************************************************************************************

通过.class文件确认major,minor版本的方法

1.在eclipse中打开class文件,可查到


2.通过javap命令查看,例如javap classname -verbose > C:\major_version.txt


因此,编译及运行的java版本相同,例如,46是1.4默认编译的major版本,需要使用1.4 compiler进行编译


 


0 0
原创粉丝点击