Java Common Problems 1

java-common-problems

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#crosscomp-options
http://stackoverflow.com/questions/12770622/java-lang-unsupportedclassversionerror
http://stackoverflow.com/questions/10382929/how-to-fix-java-lang-unsupportedclassversionerror-unsupported-major-minor-versi

If we use Ant and Eclipse, we may not need to install the older Java version. In the build.xml, we can specify the compatible target version:

<target name="compile">
  <javac target="1.5" srcdir=.../>
</target>

The reported major numbers are:

Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

Source: https://en.wikipedia.org/wiki/Java_class_file#General_layout

To fix the actual problem you should try to either run the Java code with a newer version of Java JRE or specify the target parameter to the Java compiler to instruct the compiler to create code compatible with earlier Java versions. For example, in order to generate class files compatible with Java 1.4, use the following command line:

javac -target 1.4 HelloWorld.java

With newer versions of the Java compiler you are likely to get a warning about the bootstrap class path not being set. See https://blogs.oracle.com/darcy/entry/bootclasspath_older_source

IN eclipse project=>Proerties=>java compiler; set "the compiler compliance level" to the version according to your jre or jdk.

Project -> Properties -> Java Compiler Enable project specific settings. Then select Compiler Compliance Level to 1.7, 1.6 or 1.5

In Eclipse, I just went to menu command Window -> Preferences -> Java -> Compiler and then set "Compiler compliance level" to 1.6.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License