****************************************************************************************************************************************
The exception "Unsupported major.minor version
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.
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
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:
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
Run # javap -verbose
note: provide the name without extenstion, so use myclass instead of myclass.class
Check the major version collected in below table
Major version | Java |
46 | Java 1.2 |
47 | Java 1.3 |
48 | Java 1.4 |
49 | Java 5 |
50 | Java 6 |
51 | Java 7 |
******************************************************************************************************************************************************
通过.class文件确认major,minor版本的方法
1.在eclipse中打开class文件,可查到
2.通过javap命令查看,例如javap classname -verbose > C:\major_version.txt
因此,编译及运行的java版本相同,例如,46是1.4默认编译的major版本,需要使用1.4 compiler进行编译