How do I compile for compatibility with older versions of Java?

Question ID : 57
Created on 2009-08-31 at 6:00 PM
Author : Veryant Support [support@veryant.com]

Online URL : http://support.veryant.com/support/phpkb/question.php?ID=57



Question:
When I run my program with an older version of the Java runtime environment I get the following error:

  java.lang.UnsupportedClassVersionError: ABCPROG has been compiled by a more recent version of the Java Runtime (class file version 61.0),
What can I do to resolve this?
How can I see the version number in the .class file?

Answer:
You can use the -jo compiler command line option in order to specify options to be passed to the Java compiler such as:
"-source" and "-target".

For example, to compile for compatibility with Java 1.8, add the following to your compile command line

   -jo="-source 1.8 -target 1.8"
To compile a program named MYPROG.cbl:
   iscc -jo="-source 1.8" MYPROG.cbl
(you can omit "-target 1.8" since it is the default when specifying "-source 1.8")

Run this command to get the supported releases for the -source option
   javac --help -source

In order to check the version number in a .class file you can use the javap utility that is distributed with the JDK.
For example, the following command will report the version of a program named MYPROG.
   javap -verbose MYPROG | grep major
or run
  javap -verbose MYPROG
and the version numbers will be reported in the first 5 lines.

Note that MYPROG.class must be in the class path.
You can specify a class path with "javap -cp".

The major version is mapped to the Java SE version here.



Back to Original Question